Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to refresh the JButton text among other things.

 
Greenhorn
Posts: 15
Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm trying to refresh the text on a JButton.

Here's an example of what I'm trying to do. The primary button text is pulling from an array. After I change the value in the array I want the button text to change. Not sure of the syntax to do this.


Also, is there a way to close the JPanel upon clicking the "Add" button? This is going into a game and it's pretty clunky for the user to have to click the X every time.

Any help would be appreciated.

Thanks.
 
Sheriff
Posts: 26951
83
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lonnie Wood wrote:I'm trying to refresh the text on a JButton.


Then you call the JButton's "setText(String)" method.

Also, is there a way to close the JPanel upon clicking the "Add" button? This is going into a game and it's pretty clunky for the user to have to click the X every time.


A JPanel can't be closed. However your mention of "click the X" suggests that you actually want to close the JFrame. So, going back a step, I'm going to guess that you want to use this code to prompt the user for something before you carry on. If that's the case then don't use a JFrame. Use a JDialog instead. JDialog is specifically designed to be a "dialog box" which goes away once the user clicks "OK" or whatever.
 
Marshal
Posts: 74654
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you have a Listener which appears to create a new Question object and never does anything with it?

I think this thread would sit better on our GUIs forum: moving.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic