Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck if JRadioButton is checked
    text
    copied!<p>I'm begining with Java and I'm having a simple problem, I wanna get wether my JCheckBox is selected or no. For this I know I have to use comboBox.isSelected(), but in the method I wanna use it, I cannot make reference to the object JCheckBox. Here's the code:</p> <pre><code>import java.awt.BorderLayout; public class AgregarPlato extends JDialog { private final JPanel contentPanel = new JPanel(); public static void main(String[] args) { try { AgregarPlato dialog = new AgregarPlato(); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } public AgregarPlato() { setBounds(100, 100, 546, 459); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(null); JRadioButton radio = new JRadioButton("\u00BFDesea llevar Stock?"); radio.setFont(new Font("Tahoma", Font.PLAIN, 11)); radio.setBounds(91, 207, 168, 23); contentPanel.add(radio); { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton aceptarButton = new JButton("Aceptar"); aceptarButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (radio.isSelected()) { System.out.println("It doesnt work"); } } }); aceptarButton.setActionCommand("OK"); buttonPane.add(aceptarButton); getRootPane().setDefaultButton(aceptarButton); } { JButton cancelarButton = new JButton("Cancelar"); cancelarButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); cancelarButton.setActionCommand("Cancel"); buttonPane.add(cancelarButton); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload