• 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

Change content dynamically on JPanel (Currently it opens in a new window)

 
Ranch Hand
Posts: 34
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi people, I'm working on a little project to apply some of the skills which I've learnt over the last few weeks. I want to create a GUI interface where I am able to click something like Help>About and then on the JPanel it would like a small about paragraph or so.

I think I'm close but unforuntately it 'writes' or changes the label by opening up a new GUI. How do I dynamically update/change the label on the current gui?

I have two classes, here is my first class:



And this is my second class:



So this is how it loads by default:

and when I click help>about this is what appears (new window opens up):

How do I fix this?

Thanks guys!
 
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
Welcome to the Ranch.
You can change the current text of a JLabel by invoking
 
Benjamin Scabbia
Ranch Hand
Posts: 34
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:Welcome to the Ranch.
You can change the current text of a JLabel by invoking



Thanks for reply and warm welcome!

Sorry I'm not 100% sure what you mean...

This is my Test class:



and in my main class I called the method

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

it 'writes' or changes the label by opening up a new GUI.



Because that is exactly what you are telling the code to do. Your code is:



Any time you use the "new" keyword you create a new instance of the Object. You don't want to create a new instance just update the existing label.

So all you need is:


 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic