• Post Reply Bookmark Topic Watch Topic
  • New Topic

Change JLabel.  RSS feed

 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone. I have simple swing window with JMenuBar with few submenus. And not...at start, if you run this program it will show only window with few texts etc, But I dont know how can I create something like function whitch will show another JLabel with X1/X2/X3 button (just sample names), after pressing sub menu in my menu, i know how to create action listener etc.

And if you will click another button from my submenu it should show another JLabel with anothers buttons..

Sorry if it was wrong explained.

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to do the following:

User clicks Menu A; the label displays text "You clicked A"
User clicks Menu B; the label displays text "You clicked B"
and so on.

Create an instance of a JLabel.
Add it to the content pane.
In your action performed invoke label.setText().
Do not keep switching the labels. Just change the text.

should show another JLabel with anothers buttons..

You cannot have buttons inside a label. Either you are thinking incorrectly or I am not able to understand your requirement.
 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you got my point thanks for reply.

But now i want to change buttons after clicking.

For example. At start we had :

A button and B button

after clicking "User clicks Menu B;" and buttons A and B should disappear and there should be:

C button and D button

And if you click again A menu..it will show you again A and B button.

 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's the setVisible(boolean) method. Or you could have different JPanels for each menu item and a CardLayout to switch between them. Or there's probably lots more ways to implement your requirement. But I can't recommend any of them because I don't understand why you want to do whatever it is.

Have you read the Swing tutorial? I would recommend you start there.

Also, you might want to have a closer look at the GUI applications you use every day. Do they have disappearing buttons in them? If you design a GUI which is more like the usual sort of thing, you'll find it a lot easier to implement than a non-standard GUI which does unusual things. Not to say you can't do unusual things, it's just that you should be able to do the usual things and recognize when a GUI feature is strange.
 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great, CardLayout is my solution, thank you guys.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!