aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to  add slider / knob to  JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to  add slider / knob to  JScrollPane" Watch "How to  add slider / knob to  JScrollPane" New topic
Author

How to add slider / knob to JScrollPane

Manoj Tare
Greenhorn

Joined: Feb 04, 2003
Posts: 26
Hi Friends ,
I have problem with JscrollPane.
I'm adding image on JPanel
JPanel added to JscrollPane
If Image size is bigger than Panel it shows scroll bar but when image size is less than Jpanel
it only show gray scrollPane . It without knob/ slider .
How to add knob/ slider if image is less than Jpanel or always .

I tried
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZANTAL_SCROLLBAR_AS_NEEDED
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS
ScrollPaneConstants.HORIZANTAL_SCROLLBAR_ALWAYS
propertiecs but it shows only gary scrollPane .
Pls send any sample code or some tipes for this .

Thanxs
Manoj
raj varma
Greenhorn

Joined: Jan 05, 2003
Posts: 28
As far my knowledge, Knob will appear ONLY IF the image size is larger than specified area of JScrollPane.
There is no way to show knob in a condition that image size is smaller than JScrollpane area.
Salvatore Johansen
Greenhorn

Joined: Feb 28, 2003
Posts: 3
This should help...
Basically, the default behavior is to scroll if needed... The link below will provide you the foundation to force scroll bars and knobs.
<QUOTE>
That is, the scroll pane has no scroll bars because the client's preferred size is big enough to display the entire client.
</QUOTE>
http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html
Manoj Tare
Greenhorn

Joined: Feb 04, 2003
Posts: 26
Thanxs for link .
I tried some code from that.
but it can't work.
I used following code for setting size .
this.setPreferredSize(new Dimension(newImg.getWidth()+10,newImg.getHeight()));
this.revalidate();
and then called PaintComponent(Graphics g) method.
Method setPreferredSize()
not setting size for Panel ,
it set's same size (previous size) for panel.

Is there way to setPreferredSize for Jpanel
Joseph Savard
Greenhorn

Joined: Aug 21, 2002
Posts: 1
Is (this) a JPanel??
>I used following code for setting size this.setPreferredSize(new Dimension(newImg.getWidth()+10,newImg.getHeight()));
>this.revalidate();
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--javax.swing.JComponent
|
+--javax.swing.JPane
[ March 01, 2003: Message edited by: Joseph Savard ]
Manoj Tare
Greenhorn

Joined: Feb 04, 2003
Posts: 26
Hi frinds,
Yes This is JPanel
I'm adding image in Jpanel and this panel then added to JScrollPane .
Problem is setPerferedSize(width,height)
is applied for panel means panel size not changing
so if image size is bigger than than Jpanel, scrollPane not showing scrollbars .
Manoj
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to add slider / knob to JScrollPane