Questions tagged [jtogglebutton]

The JToggleButton represents button that can be toggled, similar to a check box.

JToggleButtons can be placed wherever checkbox functionality is desired in a button. When the user presses a JToggleButton, then the button stays visually pressed. When the user presses again, then it is visually unpressed.

Depending on the user's look and feel, the button may look like a normal button, or it may look completely different.

122 questions
0
votes
1 answer

Making Multi-Coloured Buttons in Java

I want to create a grid of squares in my Java Swing GUI. I need to toggle their state so I'm thinking a JToggleButton is appropriate for each of the squares. The problem that I have is that I want to partially colour each toggle button according to…
Steve W
  • 1,108
  • 3
  • 13
  • 35
0
votes
0 answers

CustomButton cannot be converted to JButton

I want to customize a button as the code shows below public class CustomButton extends JToggleButton{ public CustomButton() { } public void paintComponent(Graphics g){ Color bg,text; if(isSelected()){ bg =…
Alaey
  • 41
  • 2
  • 8
0
votes
1 answer

JToggleButton background color when selected

I have a JTogglebutton where I set the initial background color to red. I have an action routine that flips between red and dark red. Basically, if the button is selected, it is red. Not selected, it is dark red. The code runs, but whenever the…
John W
  • 42
  • 1
  • 9
0
votes
1 answer

In Java Swing, is there a way to toggle ButtonGroups being mutually exclusive?

From what I understand, if you want to have to select one option, you put it in a ButtonGroup, and if you don't, you don't use a ButtonGroup. But I want it so that multiple can be selected but only if you selected something else in another area. Is…
DanielLC
  • 5,801
  • 5
  • 18
  • 16
0
votes
1 answer

Key Listener keeps listening for more keys, and i can't figure out how to stop it from doing so

So i made a little sudoku game where I've used toggle buttons to take input. Basically when a toggle button is toggled, a key listener is activated that listens for keys 1-9. Problem is, after the key is entered, i've used…
0
votes
1 answer

Memory Game : disable JToggleButton after a match

I am currently trying to program a memory/matching game. I am having a problem with trying to figure out how to disable the button after the user has found matching cards. I understand that I need to store the value of the first click and compare it…
0
votes
2 answers

Is it possible to make a JToggleButton deselect other JToggleButton to have a similar effect to traditional radio buttons?

I have the following JDialog implemented: [ jToggleButton1 ] [ jToggleButton2 ] [ jToggleButton2 ] I would like that when user presses (-toggles-) any of the JToggleButtons the other two change their state to unselected. This would emulate…
M.E.
  • 4,955
  • 4
  • 49
  • 128
0
votes
0 answers

How do I change the color of a disabled jToggleButton?

I'm working on a game that disables JToggleButton buttons when I click on them, but I want the buttons to also change color when they're disabled. I disable a button with: private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) { …
Marco
  • 11
  • 2
0
votes
1 answer

Timer does not start when implementing memory game with JToggleButton

I am trying to create a memory game where you have 12 togglebuttons. If you click one button, the icon would change. If two icons match then both are flipped. However, if they do not match, then a timer starts for 1.5 secs then switch both…
Allen
  • 35
  • 6
0
votes
0 answers

ImageIcon array. How to grab images from source folder and set JToggleButton icon?

public class DisplayPanel extends JPanel { private final static ButtonGroup buttonGroup = new ButtonGroup(); static JRadioButton [] radioButtons = new JRadioButton [4]; static JLabel [] labels = new JLabel [4]; …
Thomas Walker
  • 145
  • 1
  • 7
0
votes
1 answer

How to get JComboBox last ( previous) selection state

I know that subscribing for ItemListener on the checkbox one can get the ItemEvent.SELECTED/DESELECTED state inside the method: public void itemStateChanged(ItemEvent e) { if(e.getStateChange()==ItemEvent.DESELECTED){ } .... } But what I…
mediterranean
  • 123
  • 1
  • 9
0
votes
1 answer

jToggleButton isSelected and setBackground is not working as expected

I am trying to make it so that the button will change color whenever it is selected. I tried using an if statement to see if the button is selected, and if it is, it will set it to red. However it doesn't work. if(jToggleButton1.isSelected()) { …
Al-x
  • 19
  • 7
0
votes
0 answers

JToggleButton opening but not Executing MouseListener Method

So basically I am writing a minesweeper game currently and am having a problem with my JToggleButtons. Sometimes when they are pressed (like every 10%), they do this random thing where they open, but do not follow/execute the mouseListener method…
Michi
  • 13
  • 4
0
votes
0 answers

dynamically changing a JToggleButton's icon

i have a problem in changing the icon of a JToggleButton at runtime without clicking this latter or changing its state i've tried to do it with static method but it doesn't change i just wanna know is there a way to do so in java??? this the…
Karim
  • 637
  • 1
  • 5
  • 13
0
votes
1 answer

Creating and adding JToggleButton to a panel programmatically

I'm developing a software where a user has to setup the software according to the users' need before using it. When the user clicks on a menu item the software throws a JDialog and asks for a user input and the software stores the input. This works…
D.R.
  • 55
  • 8
1 2 3
8 9