-1

I am developing a small desktop application in Java using Netbeans. On my jframe i have various pannels and one scroll panes. The purpose of this JScrollPane is to show some visual elements to its users. I achieve this by following the below steps in sequence:

  1. Drag and drop JScrollPane at desired location of my JFrame
  2. Adjust the size of JScrollPane according to my needs.
  3. Write a new java class and extend that class with JPanel
  4. Override the public void paintComponent(Graphics g) method
  5. Then i add that panel to above JScrollPane,

using following code:

JPanel jpnl = new myClass();
jScrollPane2.setViewportView(jpnl);
jScrollPane2.repaint();

Now every thing is working fine as per my requirements, the only thing which is lacking is that when my drwaing is big then no sroll bars are shown at JScrollPane. This is my first application and i don't know much about Java, so any guidence regarding what is missing would be highly appreciated

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Jame
  • 21,150
  • 37
  • 80
  • 107
  • please learn java naming conventions and stick to them – kleopatra Dec 13 '11 at 12:30
  • step 2 is incorrect (you never adjust/set a size, that's the task of a appropriate LayoutManager) Assuming that "my needs" have something to do with the content drawn in paintComponent - override the panel's getXXSize to return those "needs" (aka: sizing hints to be used by the manager) – kleopatra Dec 13 '11 at 12:34

1 Answers1

1

Remember to add the required component to the JScrollPane object, and the scroll pane object to the panel. Also, it could be that you need to change the scroll bar policy: use scroll pane's setHorizontalScrollBarPolicy() and setVerticalScrollBarPolicy().

Consult the JScrollPane documentation for these methods.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
DaedalusUsedPerl
  • 772
  • 5
  • 9
  • 25