• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get Reference of JScrollPane from JPanel  RSS feed

 
Himanshu sGarg
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have added a JScrollPane and added a JPanel to JscrollPane. How can I get reference to Jscrollpane from the JPanel in order to access properties of Jscrollpane?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is kind of odd. What properties are you trying to access? What problem are you trying to solve?
 
Himanshu sGarg
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want that the buttons added to Jpanel inside jscrollpane should move while I scroll the Jscrollpane, i.e. the buttons in jpanel should always be visible while I scroll the scrollpane.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This can be done in (minimum) two ways
1) Create a panel with BorderLayout
2) Add scrollable content to the scroll pane
3) Add scroll pane to center of panel in #1 above
4) Add buttons to North, South, East, West of panel #1 above as per design.
This way, even if the content scrolls, your buttons dont.

The other way would be to pass to declare the scroll pane as an instance variable. Can you show us your panel code which has the scroll pane added to it?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
5) Set a columnHeaderView
6) Set a rowHeaderView

Himanshu, I suspect that you are mucking around with a null layout and setBounds(...). Don't. Use a proper layout manager or a combination of them.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh wow! I agree Darryl has the better solution. I had completely forgotten about the column header
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not necessarily a better solution, and may not be acceptable of both the H- and V-scrollbars are active. The column header scrolls horizontally, and the row header scrolls vertically to sync with the viewportView.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!