Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / September 2003

Tip: Looking for answers? Try searching our database.

Switching between JLabel and JComboBox at runtime?

Thread view: 
Andreas - 27 Sep 2003 15:30 GMT
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
Erik A. Brandstadmoen - 27 Sep 2003 19:19 GMT
> 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.

> 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.
Andreas - 28 Sep 2003 11:47 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.