JScrollBar horizontal

StrikeTom

Bekanntes Mitglied
Hallo Leute,
ich habe eine JScrollBar, auf die ich ein JPanel "packe".
Das funktioniert schon soweit.
Allerdings soll die Srollbar nur Horizontal sein.
Weiß jemand wie???:L
Danke schonmal im vorraus:)
 

eRaaaa

Top Contributor
How to Use Scroll Panes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

Of the constructors provided by JScrollPane, these two let you set the scroll bar policies when you create the scroll pane:
JScrollPane(Component, int, int)
JScrollPane(int, int)
The first int specifies the policy for the vertical scroll bar; the second specifies the policy for the horizontal scroll bar. You can also set the policies dynamically with the setHorizontalScrollBarPolicy and setVerticalScrollBarPolicy methods. With both the constructors and the methods, use one of the following constants defined in the ScrollPaneConstants interface (which is implemented by JScrollPane):

Code:
Policy	Description 

VERTICAL_SCROLLBAR_AS_NEEDED 
HORIZONTAL_SCROLLBAR_AS_NEEDED 	The default. The scroll bar appears when the viewport is smaller than the client and disappears when the viewport is larger than the client. 

VERTICAL_SCROLLBAR_ALWAYS 
HORIZONTAL_SCROLLBAR_ALWAYS 	Always display the scroll bar. The knob disappears if the viewport is large enough to show the whole client. 

VERTICAL_SCROLLBAR_NEVER 
HORIZONTAL_SCROLLBAR_NEVER 	Never display the scroll bar. Use this option if you don't want the user to directly control what part of the client is shown, or if you want them to use only non-scroll-bar techniques (such as dragging).
 

eRaaaa

Top Contributor
Habe ich dich jetzt falsch verstanden?
Also im Moment sind beide Scrollbars aktiv, wenn sie gebraucht werden, richtig? Du willst jetzt aber, dass es nur eine horizontale Scrollbar gibt? Dann setze wie schon gesagt, die Policy für die vertikale auf "never":

Java:
setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
//und evtl. :
setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
//wenn die horizontale immer sichtbar sein soll!

vermutlich habe ich dich aber auch falsch verstanden?!???:L
 

StrikeTom

Bekanntes Mitglied
Entschuldigung, dass ich mich nicht verständlich ausgedrückt habe:oops:.
Danke, es funktioniert aber nur halb, da ich, wenn ich jetzt mehrere JLabel zu dem JPanel hinzufüge, dann macht er mir keine Scrollbare JScrollBar, sondern lässt diese nicht scroll bar.
 


Schreibe deine Antwort... und nutze den </> Button, wenn du Code posten möchtest...

Ähnliche Java Themen

Neue Themen


Oben