• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Swings newbee : Changing window components

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
shukla raghav
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • 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: 205
  • Mark post as helpful
  • send pies
  • 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: 3111
26
  • Mark post as helpful
  • send pies
  • 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: 21842
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JComponent is enough.
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!