 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Andreas Guest
|
Posted: Sat Sep 27, 2003 2:30 pm Post subject: Switching between JLabel and JComboBox at runtime? |
|
|
Hi,
I have searched the archives, but did not find the answer to my problem.
So:
In a JPanel (in a JInternalFrame) I use a JComponent.
At startup a JLabel is set to this JComponent (JComponent theJComponent =
theJLabel;) and the JLabel is properly shown.
When a user performs a certain action (like pressing a button) I want to
display a JComboBox instead of this JLabel (i.e. in the same place).
I seem to be missing something, because I can't get it to work. After
setting theJComponent = theJComboBox, I have tried all the
validate/invalidate/revalidate/repaint on both the JComboBox, the
JComponent and the JPanel, but nothing happens.
Obviously I am doing something wrong. How should this be done?
I am using JDK1.3.1.
Thank you.
/Andreas
|
|
| Back to top |
|
 |
Erik A. Brandstadmoen Guest
|
Posted: Sat Sep 27, 2003 6:19 pm Post subject: Re: Switching between JLabel and JComboBox at runtime? |
|
|
Andreas wrote:
| Quote: | In a JPanel (in a JInternalFrame) I use a JComponent.
At startup a JLabel is set to this JComponent (JComponent theJComponent =
theJLabel;) and the JLabel is properly shown.
|
I assume that what you do after this is to add the JLabel to the JPanel.
| Quote: | When a user performs a certain action (like pressing a button) I want to
display a JComboBox instead of this JLabel (i.e. in the same place).
I seem to be missing something, because I can't get it to work. After
setting theJComponent = theJComboBox,
|
What do you want to achieve by this? The only thing you achieve is to
make the reference that once pointed to the JLabel that is displayed on
the JPanel to point to another Component, i.e. the JComboBox. You
haven't done anything with the components in the JPanel.
You need to remove the JLabel and add a JComboBox in the same spot. I
don't know what the rest of your layout looks like, but this should be
no problem using a GridBagLayout or a CardLayout.
Erik.
|
|
| Back to top |
|
 |
Andreas Guest
|
Posted: Sun Sep 28, 2003 10:47 am Post subject: Re: Switching between JLabel and JComboBox at runtime? |
|
|
"Erik A. Brandstadmoen" <erikbra (AT) ifi (DOT) uio.no> skrev i meddelandet
news:dxkdb.26196$os2.361785 (AT) news2 (DOT) e.nsc.no...
| Quote: | What do you want to achieve by this?
You haven't done anything with the components in the JPanel.
|
Of course you are correct, and now it works like it should.
This was embarrasingly stupid, and I guess I was just having a bad brain
day (as opposed to bad hair day) or something.
I'm gonna go and hide now.
Thanks a lot Erik. Much appreciated.
/Andreas
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|