2

I have a JPanel inside JScrollPane. Inside the JPanel are numerous JButtons. However, these JButtons are set to NOT VISIBLE (jbutton.setVisible(false)) when the JPanel and JScrollPanel are initialized. The JButtons are only set to VISIBLE (jbutton.setVisible(true)) when another class triggers this.

However, although these JButtons are getting successfully added and set to visible on the JPanel, they are not visible on the JPanel or JScrollPane. My guess is that when the JScrollPane adds the JButtons, the JButtons are set to NOT VISIBLE, and even if the JButtons are set to VISIBLE, the JScrollPane does not detect they are.

Is there a way of dynamically changing the visibility of the JButtons in the JPanel inside the JScrollPane?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
minoue10
  • 81
  • 1
  • 10
  • Share some code so we have a better idea of what you are doing. It shoulda like your "adding" the panel to the scroll pane instead of setting the scroll pane's viewport's view – MadProgrammer Mar 25 '13 at 21:38
  • For better help sooner, post an [SSCCE](http://sscce.org/). Maybe use a `CardLayout` instead. – Andrew Thompson Mar 25 '13 at 23:16

1 Answers1

3

However, although these JButtons are getting successfully added and set to visible on the JPanel, they are not visible on the JPanel or JScrollPane. My guess is that when the JScrollPane adds the JButtons, the JButtons are set to NOT VISIBLE, and even if the JButtons are set to VISIBLE, the JScrollPane does not detect they are.

  • have to call revalidate() and repaint() to JPanel, as last code lines after all changes are executed

  • have to change setUnitIncrement for JButtons in JPanel wrapped in JScrollPane, because scrolling is too slow, isn't natural

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • I've been calling repaint and revalidate to both the JPanel and the JScrollPanel as last code lines. Hasn't worked... Why do I have to change the setUnitIncrement for JButtons...? I can scroll through the panel well, it's just my Jbutton isn't showing up.. – minoue10 Mar 25 '13 at 21:25
  • Sounds like possible layout issue – MadProgrammer Mar 25 '13 at 21:30
  • then there musst be another issue, nothing clear from your question, hmmmm oooooonly are the JPanel added as JScrollPane.setViewportView(JPanel), otherwise for better help sooner post an [SSCCE](http://sscce.org/), short, runnable, compilable – mKorbel Mar 25 '13 at 21:30
  • `Why do I have to change the setUnitIncrement for JButtons`, please blue colored are link to another post or www sites, did you read linked post, tried code example – mKorbel Mar 25 '13 at 21:31
  • Yes, I have, and it doesn't fix my problem. Will look into this a bit more. – minoue10 Mar 25 '13 at 21:35