• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

add JCheckBoxes, clear, re-add JCheckBoxes to JScrollPane, but can't see them

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all.

Would you mind helping me with this? In method updateTopicsSubjectsPanel( ) at line 375 I'm trying to remove all JCheckBoxes and then add a new list of JCheckBoxes.

I'm having trouble finding the right methods to call afterwards to have the JScrollPane display the new check boxes.

I've tracked pack( ) validate( ) revalidate( ) repaint( ) etc. but i can't get it to work. The JScrollPane remains blank.

Note: a JComboBox "topicGroups" listener'  public void actionPerformed(ActionEvent e) calls updateTopicsSubjectsPanel( ) to populate the check boxes in JScrollPane "subjects_scroll" based on the value chosen in "topicGroups"

I've pasted the code for the JPanel class below.

Thank you very much for your time.

 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can the code be compiled and executed for testing?
I don't see a main method.

Also the frame size is too large for my screen.
 
Ryan Chidley
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.

I'm trying not to post all my classes because they involve a database as well as file paths.
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't post any more classes.  Add a main method for testing.
Comment out D and hardcode some simple ArrayLists for testing.

Also the frame size is too large for my screen.  Please reduce to 1000x600
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We don't care about your application, only the stated problem.

So you:

1) create a frame with a panel containing a couple of checkboxes
2) then you create a button and add it to the frame.
3. Then you add an ActionListener to the button that will clear the panel and add the new check boxes to the panel

The total length of the program will be about 20 lines of code. So it will be easy to debug and get working. If you have problems then you has a small piece of code to post. We don't have the time to look at 400 lines of code to see what you might be doing wrong.

Once you understand how it works, you apply the knowledge to your real class.

Also,  you may want to consider using a CardLayout. This is the normal way of swapping panels in a frame. Read the Swing tutorial o How to Use CardLayout for working examples.
 
Ryan Chidley
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.

Per your request please see below. Thank you for your time.

 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, that compiles and executes.  
Now what does a user have to do to create the situation you are asking about?

Note:  The contents of the lower right panel are squeezed too small to see.
 
Ryan Chidley
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When the user chooses a value from the drop down "Groups of Topics" the list of check boxes on display in Topics.Subjects pane in the upper left is supposed to populate.

 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you ever tried adding JCheckBox objects to a scroll pane?
What happened?

Can you add some check boxes in the code to show that it works?
 
Ryan Chidley
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It does not appear to be possible to add JCheckBoxes to a JScrollPane, so I think that was indeed the problem.

I assumed it was possible, and that was my error.

I have added a test JCheckBox to the upper left pane - as you suggested -  and seen that list dynamically change as it was supposed to after I replaced JScrollPane with JPanel.

Thank you very much for solving my problem.

Thank you very much for your time.

There was no need to change the method in question. frame.pack( ) is sufficient. I would post the corrected test code but I'm out of pie for now.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic