• Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI - Components  RSS feed

 
Christian Long
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I want to add a component 2 times to a Container.
for e.g:
Container con = new Container()
JToolbar tb1 = new JToolbar()
JButton button1 = new JButton("My Button")

tb1.add(button1)
con.add(tb1)
con.add(button1)


Is there a way to add 'button1' 2 times?
[ October 26, 2007: Message edited by: Christian Long ]
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't add components to a user interface twice. You'll need to add two identical buttons.

However, if you start using Action instead, you can do something quite similar to adding a button twice.

Basically, you create an Action (mostly a sub class of AbstractAction), and then add two buttons with only that action in their constructors:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!