jbutton

Java actionListener for a nameless JButton?

Hey everyone, I was wondering if there is a way to implement an action listener for a Jbutton without a name. For example, I have the following for loop that creates a button for each letter of the alphabet. for (int i = 65; i < 91; i++){ alphabetPanel.add(new JButton("<html><center>" + (char)i)); } Is there a way that I can add...

JButton expanding to take up entire frame/container

Hey everyone. I'm trying to make a swing GUI with a button and a label on it. im using a border layout and the label ( in the north field ) shows up fine, but the button takes up the rest of the frame (it's in the center field). any idea how to fix this? ...

Swing JButton: Icon above Text

How can I create a JButton in Swing with the icon above the text? ...

Java GUI - General

Hello all you helpful folks @ stackoverflow! Best resources for Java GUI's? Looking at the Java Documentation, it is pretty easy to figure out the basics of JButtons, JFrames, etc but grasping the concepts of accessing JComponents from a frame, what creating a different panel does, etc is not very easy to understand. Is there some tut...

Java GUI Creating Components

I hope it is correct term-wise to say that components in a GUI is like JButton, JPanel, JTextField, all that good stuff. I want to create a text field that takes in an integer. Then a submit button can be pressed and based on the integer that was inputted, create that many textfields in a popup window or whatever. I have no clue, could...

How do I assign Enter as the trigger key of all JButtons in my Java application?

I'm writing a Java Swing application using the Metal look-and-feel. Every time there is a JButton in my application the user uses the Tab key to move the focus to the button and then hits the Enter key. Nothing happens! If he hits the Space key the button events are fired. How do I assign the Enter key to trigger the same events as the S...

managing parent frame from child frame on java swing

I have a jframe (parent) which creates an input frame (child) where I get some parameter. In the "child" frame I have "ok" and "cancel" buttons. When "ok" button is pressed, the parent frame needs to be updated with new data. What is the best way to do that?? ...

How to change the image of a JButton?

I'm working on a memory game program. I have 30 JButtons on a JPanel. When the user is clicking and finds a match (meaning two buttons with the same image) I want to change the image on the JButton to a different image. However this does not happen while the program is running. How can I do this? I was doing this: cards[i].setIcon...

Resetting an arry of JButton Labels and making all active again

Hi, when i play my game i allow the user to click the buttons which then sets a o or an x as the label and then each button becomes in active as to not allow the user to clik it again and again however when i get to 9 goes and its a draw a message box pops up and says draw but i cant seem to get the buttons to restore themselves to the ...

Create an array of JButtons with the Netbeans 6.5 GUI Builder

Hello, I want to create an array of JButtons with the GUI Builder (not actually writing the code, but drawing it). I can only figure out how to change the name of the element, not add it to an array. Thanks. ...

Is it possible to include JButton in a JTable?

I have a JTable that stores the results of a database query, so far so good. What I want is for the last column in each table to have a clickible JButton that will open the edit screen for the object represented in that row, and that means the button will need to know the details of the first column in the table from its own row (the ID ...

Multiple java Applets handling

I'm creating a simple java game Applet that has multiple Panels, The main game Panel has 4 JButtons that lead to the rest of the Panels when they are clicked. when the program runs, the four Panels are initialized 1st inside the init(), and inside each Panel initialization, I made all the Jcomponents invisible but only the main applet. ...

make a button round

hi, im trying to make a JButton round at the (x,y) corrds of (150,210). i want the button to be an oval of the size (40,40). and the buttons background color red. it doesnt need text so i should get a button to what ever size i want right. i am using a panel and i set the setLayout to null setLayout(null) i checked google and it brou...

How do I switch panels inside a frame depending on a button action?

I have created an application that has a toolbar, menubar and content area. I have added the menu and toolbar to the application window, but I am stuck with displaying the panel in content area based on the button action (like add, display) which is clicked through the toolbar. Is this a right way to do this? Is there any better way to d...

How to create a JButton extension with rounded corners?

This is a continuation of the question "Java rounded Swing JButton". I have searched for an extension of javax.swing.JButton which will inherit all runtime behavior and just override drawing of the corners. Using the code given by noah.w on sun forums page the result looks like this: I'd like to be able to have the same gradient in t...

event attached with button clicking

I have a JFrame in which there are 2 textfields and 1 JButton. Users need to enter some string in the textbox. When user clicks the button in the JFrame then these strings get displayed in a JTable. I am not getting what code shall i write with button clicking. Please help me. Thanks. ...

Changing the color of a font and making it underlined

I need to make a font underline and blue for a hyperlink in one of my JButtons, but it seems the font class has no obvious way to do this. I can't use attributedtext because I'm not going to be displaying this with Graphics class. Is there anyway I can accomplish this? I just need the title of my JButton to be blue and underlined. ...

Adding a child component to a JButton

Is it possible to place a child component inside a JButton and make it transparent to a subset of mouse events so that: The child component receives MouseMotionEvents (so it can respond by modifying a displayed image) Clicking still depresses the JButton "behind" the child component If you add the child component to the button but ma...

How to get JButton default background color ?

I use this : myButton.setBackground(myColor) to change the button background color to my color, how to find it's original default background color so I can change it back ? I know I can save it's default background color before I change and use that, but I wonder if Java stores it some where so maybe I can call something like : myButton....

Using <html><u> tags to make button text underlined, caused button to take up entire JToolBar

I need to have a button whose text is underlined and the only way I could find to do this in Java was to use and tags but when I do this, it causes the button to take up as much room as is left in the JToolBar even though the text is short and it should only take up a small amount of space. Here is how I create the the Button. ...