• 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

Runtime Changes to Your GUI

 
Greenhorn
Posts: 4
Mac Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Can Swing components be generated dynamically at run time? A simple example would be, a mouse-click inside a Text Field would draw a new Text Field. Again, a mouse-click inside this new Text Field would draw a new Text Field again. There is no limit on number of created Text Fields.

Here they describe how to replace or hide a component but that means that number of components is know during coding (look for Runtime Changes to Your GUI):
http://java.sun.com/docs/books/tutorial/uiswing/layout/group.html

Thank you.
 
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a question that comes up a lot. It seems to be a poorly documented aspect of java. I understand it can be done, but i can't tell you how. I'm interested in how this thread turns out.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would suggest experimenting with an ArrayList<JTextField>. Add a listener to your first one and in the actionPerformed method add a new JTextField to the ArrayList as well as set up it's listener and add it to the panel. Just a thought, I haven't really ever tried to do something like this.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Can Swing components be generated dynamically at run time?

simple example using buttons

 
W Pearce
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
using the method I suggested above (and a little free time i had this afternoon) i came up with this as a MouseListener



when i added that to my ArrayList<JTextField> it worked well.
 
reply
    Bookmark Topic Watch Topic
  • New Topic