Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add slider / knob to JScrollPane

 
Manoj Tare
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic