• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to refresh the JButton text among other things.

 
Lonnie Wood
Greenhorn
Posts: 15
Chrome
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49827
69
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic