aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to refresh the JButton text among other things. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to refresh the JButton text among other things." Watch "How to refresh the JButton text among other things." New topic
Author

How to refresh the JButton text among other things.

Lonnie Wood
Greenhorn

Joined: Feb 16, 2011
Posts: 15

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Oct 13, 2005
Posts: 38363
    
  23
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to refresh the JButton text among other things.