I have created an array of buttons (JButton[] jb = new JButton[100]) and I want to add the same action listener for all the buttons in the jb array instead of adding them one by one. Just imagine every time I click one of the buttons displayed on the screen and it will print out the index of that button
Tag: jbutton
java swing nullpointer exeption whilst adding buttons [duplicate]
This question already has answers here: What is a NullPointerException, and how do I fix it? (12 answers) Closed 8 months ago. solution So i was trying to do a java-swing-gui for a school project and therefor I have to add 72 Buttons (idk) to a JPanel element. I tried using a for-loop: but it didnt really work out and
JButton text changes on its own?
The following simple code: can always reproduce the same bug (at least for my setups, which are given below). The program is supposed to change the button text, according to the text-field’s text, when the button is clicked. The problem is that the text of the button reverts/changes back to its previous value on its own unexpectedly. The problem arises
How to use a JLabel as a JButton?
I am trying to make a program that uses a JButton, but the regular button isn’t working, so I want to make it so that when I press the JLabel it will activate a function. Answer All that you have to do is this:
How to trigger another action listener after completion of ActionListener?
I created a GUI with a JFrame, JPanel, JLabel and a JButton. I added the button and the label to the panel. I added two ActionListeners for the button. I want to execute the first action listener. Then execute the other one. Basically, I have some text that I want to output in the label, sequentially. I want for it
How to make multiple buttons work individually in Swing?
I am trying to develop an application and I have decided to learn Swing to create the GUI. I have never learnt this before, it seems quite simple but I haven’t gotten my head around ActionListener. I am trying to make the buttons respond by producing some debug text in the console. Could someone take a look and point out
Java Stop Sound Button Not Working Correctly
So I have been making a stop button recently and have been wondering how can I stop a button sound instantly when already playing. The problem : When you click the stop sound button, it only stops the next button you press. What Im Trying to Achieve : When you click the stop sound button, it stops all playing sounds.
Swing – How to modify the border color of a JButton?
How to modify the border color of a JButton? I want to get something like this: But I canĀ“t modify the color, the borde is black: And If I try to add a LineBorder or any other borde, I am not able to remove the inner border: Answer I tried an example below and all seems fine, unless you are
Is there a way to skip a mouse click for ActionListener?
I have a Tic Tac Toe GUI that lets a user play against a computer. I use an actionListener to receive the users mouse clicks on where they want to put their “X” on the board. The problem I have is, the way my code is set up, my GUI waits for a mouse click whenever it’s the computers turn
How to remove the border of an Icon in a JButton using Eclipse?
first time making a question here. First of all, Eclipse (as far as I’m aware of) don’t let you re dimension images through the design tab directly so to solve this I made a method that convert the icon from ImageIcon to image, re dimension it and then convert it back. The problem is that when I use the re