Questions tagged [jbutton]

A JButton is a common button in Java Swing.

A JButton is a common button in Java Swing that allows users to execute actions and events which have been tied to that button. It is designed to be used with ActionListener and Action classes for interacting with a gui.

Relevant Java Tutorials:

4918 questions
1
vote
1 answer

How to make these Buttons function when pressed with a key?

This is the code. The button doesnt work with key, if i dont click it first. It would be great if you could help me. I used eclipse when i created this frame This is just an example code, but I just want to know how it functions For any more…
Mergim Rama
  • 328
  • 2
  • 11
1
vote
1 answer

JButton does not change a field value

I am facing a strange problem with a simple JFrame application which has only one button in order to change a field value. When I try to debug my application, it works fine, but when I try to run it, it doesn't work and gets stuck in the while loop.…
1
vote
2 answers

JButton showing up in the wrong spot after repaint is called

I am trying to add a couple of JButton objects to my GUI program in Java and it is adding them to the JPanel (which is the main file of the program) but it is appearing in the incorrect spot. It is showing op at point [0, 0] and the action that is…
1
vote
2 answers

create Jbuttons from ActionListener variable

the mission here is to create JButtons from a String in ActionListener, but we need a way to refresh the GUI panel so it know that there is now variable for the button creater in the GUI. i have a feeling that the button creater must be in…
elektronet
  • 108
  • 13
1
vote
0 answers

Can't get my JButton to Display

I am writing a maze program that runs a mouse around the maze GUI. I'm not sure how to update an existing button in my GUI to a new color everytime the program loops. I thought I could add a new button over the top of the existing ones. Just ask me…
GTR SEVER
  • 15
  • 4
1
vote
1 answer

JButton with no background

Thank you for your kind, we learned from you many times. I have xJButton class inherits JButton class. I am doing this to add an image as icon and change it after it clicked. I do not want the blue color to be as background and also i don't want…
1
vote
0 answers

How to initialize the actions for array of buttons using for loop

I am trying to add the actionlisteners for an array of buttons by calling a method using for loop but it didn't work it showed me no outputs neither any errors just BUILD SUCCESSFUL with nothing appearing when I separated each element of the…
Basma
  • 33
  • 5
1
vote
2 answers

How to activate JTextField with a keyboard

I have two JPanels inside another JPanel. One of them has a JTextField inside, another few JButtons. I want focus to be set on the JTextField every time user starts typing (even when one of the buttons has focus at the moment).
clay_golem
  • 37
  • 1
  • 4
1
vote
1 answer

Java: NullPointerException thrown when JButton is clicked in the Flash Card Game

Details: It's a Flash Card game, each Card has question and answer. QuizCard is the class of Cards having functions like getQuestion(), getAnswer(), setQuestion(), setAnswer() and two String Instances as question and answer. A parameterised…
Palkesh Jain
  • 412
  • 4
  • 12
1
vote
3 answers

jbuttons and a jtextfield that has an action listener

I have a keypad made up of jbuttons and a jtextfield that has an action listener. When I press the button the number shows in the textfield but the next number overwrites it. Could anyone tell me how to append the text to the length 13 numbers and…
Marcus
  • 13
  • 4
1
vote
1 answer

Action listener behaving like I click every single button instead of just 1

I am fairly new to Java GUI programming, and I have started writing a program that has a GridBagLayout GUI with multiple JButtons. I have added an action listener to each button, but when I click on ANY 1 button, the program responds as though I…
BrianH
  • 337
  • 1
  • 6
  • 12
1
vote
1 answer

JButton isn't displaying Icon image in GUI

I'm trying to display a .png picture using a GUI. But I'm having trouble with the pictures displaying. I think I've isolated where I'm messing up in my instructions but can't seem to find a working solution. I am told in my instructions to...…
Mick
  • 27
  • 7
1
vote
3 answers

Adding JButtons Dynamically to JPanel based on JList values

I am working on a Java Swing application. My Requirement :- In my JFrame, I have a JList with values "One", "Two", "Three" etc. When I select one list item, I want to show "n" buttons where "n" is the value selected. Example :- If I select "Three"…
Partha Chetry
  • 136
  • 1
  • 9
1
vote
1 answer

How to repaint a Panel from inside

So I have a Calendar GUI using a borderlayout. There is a header (north) with combo boxes of month and years. When I select an item in the month combo box say, June, then it will update the calendar and repaint the center (The center has 42…
1
vote
1 answer

How can I perform the action of a button without clicking the button?

I want to perform the action done when a button is pressed without clicking the button. Asking simply, can I perform two action listeners when a single button is clicked?
shahsadpp
  • 21
  • 1
  • 2