• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to refresh the jscrollpane after altering the values

 
Lawrence Thanakumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I ma currently working with java swing . I making a list of checkboxes based on the number of elements in the arraylist and adding them to panel and then panel to jscrollpane. I ma having a button with which i am updating the content of jcheckbox and adding the updated content to the arraylist containing the real values. So after the updation i need to reload the frame or refresh the frame or else i need to refresh the jscrollpane contents for that i used frame.invalidate(),frame.revalidate(),frame.repaint() etc. So please help me in resolving this issue. Given below is my code

 
Campbell Ritchie
Marshal
Posts: 52530
119
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't make your display classes implement listener interfaces. Last year, I would have said use an anonymous class but nowadays you would use a λObviously you will have to write something in that method, and think of better names for everything.
Never use the == operator to check those Strings. Don't use action commands.
Don' use revalidate. Simply call repaint.
 
Lawrence Thanakumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done as you said but still it didnt work out. below is my coding, please help me out

 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use a null layout.

The scrollbars will automatically appear when the "preferred size" of the component added to the scroll pane is greater than the size of the scroll pane.

When you use a null layout the preferred size is always (0, 0) so scrollbars will never appear.

Read the Swing tutorial on Layout Managers for more information and working examples to get you started.

For multiple check boxes you might want the look at a panel using a GridLayout.
 
Campbell Ritchie
Marshal
Posts: 52530
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have done all sorts of things wrong, and I am not quite sure what. I tried your app and got an array index out of bounds exception.
The reason your scrolled component does not update is because you are not updating its check boxes. It isn't the scroll pane which needs updating but the labels on your check boxes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!