• 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

JPanel not being added

 
Ranch Hand
Posts: 83
Android Python Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JPanel called settingsContainer. Within that, there will be either a JPanel named caesarSettings, or vigenereSettings. vigenereSettings shows up just fine, but caesarSettings does not. At the start of the program vigenereSettings is in the settingsContainer, and caesarSettings is defined, but not used. I am using revalidate and repaint, but nothing works. Why is this?
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Why is this?


Can you post the code (wrapped in code tags) so we can see what the problem is?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rocky Rocha wrote:At the start of the program [...] caesarSettings is defined, but not used.



So there's no reason why it should ever appear in the view. Unless you did something which you think should make it appear, but you haven't told us about any such things.

Usually for Swing programs it's helpful to provide an SSCCE (<-- follow that link), as general descriptions usually miss out the specific things which needed to be done but weren't. So consider posting one here.
 
Rocky Rocha
Ranch Hand
Posts: 83
Android Python Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry. I have a combobox and I want it to change to content of a jpanel to another jpanel and switch between them based on the selection. Currently, when I tell it to switch to the vigenereSettings panel, it works fine, but even after doing revalidate and repaint on the parent panel, caesarSettings doesn't show up. Here is the code I am using:

 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're assuming that cipherComboBox.getSelectedIndex() will be either zero or one.

But let's carry on with that assumption for now, although from that code there's no evidence for that. Perhaps the caesarSettings panel just plain doesn't work? Try changing your code so that you can test that.
 
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

You're assuming that cipherComboBox.getSelectedIndex() will be either zero or one.


Add a default: case that prints a message showing the value returned so you can see.
 
Rocky Rocha
Ranch Hand
Posts: 83
Android Python Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The cipherComboBox has only 2 items in it. Therefore, it will always be 0 or 1.
Also, I have just done the test and both panels work, it's just that when I change the selection, in turn changing the panel, it doesn't show up. But upon changing it back, the original panel is shown correctly.
 
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

 it will always be 0 or 1.


API docs say:

Returns -1 if there is no selected item or ...



Or what about the day that more items are added and the code isn't updated properly?

Having a default case will catch various errors that wouldn't show up with the existing code.  
 
Rocky Rocha
Ranch Hand
Posts: 83
Android Python Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have it set so that it WILL always have a selected item, as the default is set to index 0. Either way, that is not the problem at hand. I cannot get it to change the panel. That is what I need help with.
 
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
Can you make (and post here) a small, complete program that will compile, execute and show the problem?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic