• 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

Swings newbee : Changing window components

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can some one show me the code for a SIMPLE swing application window. were there are few components includign a button. Now on clicking the button i want to change the components on the window.I dont want old components i want new components.

Lets take an example

initially the window will have

Component - 1: a non editable JTextPane with a long string

Component - 2: a button that will convert entire string in JTextPane to uppercase and display

Component - 3: another button that will remove component -1 and Component-2 and show the length of the String as a label component (component) on the same window.

Its just like while installing an application we keep pressign "next" and we keep having different components on the window.Is it possible to have all the companents removed and just shows a message.

Please make it as simple and basic as possible without complications.I would be thankfull to all who help and contribute.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> Its just like while installing an application we keep pressign "next" and we keep having different components on the window.

your search keyword would be
CardLayout
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/SwingIsAProperNoun
 
shukla raghav
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand the use of cardlayout. But just being inquisitive is it possible to change the appearance of the same Frame by changing the components it has. I dont mean chaging the properties of compnents but changing the components as just described in the example i took.

I tried removing a component from JFrame using remove(Component c) method but the system hanged. i think there was a deadlock. So i just thought if its possible or not
 
shukla raghav
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I mean can i tell my actionPerformed() method to remove a few components from the JFrame like this.

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I mean can i tell my actionPerformed() method to remove a few components from the JFrame like this.





No, because you didn't add the "jp" to the "jf". You added the "jp" to the "content", so you must remove it from the content.

In general when you add/remove individual components from a panel when the GUI is visible the code should be:



In order to invoke the revalidate() method you need to cast your "content" to a JPanel.

 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JComponent is enough.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic