new JCheckBox(String text, boolean selected) : JCheckBox « javax.swing « Java by API






new JCheckBox(String text, boolean selected)

  



import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;
import javax.swing.JFrame;

public class Main extends JFrame implements ActionListener {

  public Main() {
    JCheckBox checkbox = new JCheckBox("Show Title", true);
    checkbox.addActionListener(this);
    add(checkbox);

    setSize(280, 200);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
  }

  public static void main(String[] args) {
    new Main();
  }

  public void actionPerformed(ActionEvent e) {
    if (this.getTitle() == "") {
      this.setTitle("Checkbox example");
    } else {
      this.setTitle("");
    }
  }
}

   
    
  








Related examples in the same category

1.new JCheckBox(Action a)
2.new JCheckBox(String text)
3.new JCheckBox(String text, Icon normal)
4.JCheckBox: addActionListener(ActionListener lis)
5.JCheckBox: addChangeListener(ChangeListener lis)
6.JCheckBox: addComponentListener(ComponentListener l)
7.JCheckBox: addItemListener(ItemListener lis)
8.JCheckBox: isSelected()
9.JCheckBox: setBorderPaintedFlat(boolean b)
10.JCheckBox: setDisabledIcon(Icon disabledIcon)
11.JCheckBox: setDisabledSelectedIcon(Icon disabledSelectedIcon)
12.JCheckBox: setEnabled(boolean b)
13.JCheckBox: setIcon(Icon defaultIcon)
14.JCheckBox: setMnemonic(int mnemonic)
15.JCheckBox: setPressedIcon(Icon pressedIcon)
16.JCheckBox: setRolloverIcon(Icon i)
17.JCheckBox: setRolloverSelectedIcon(Icon rolloverSelectedIcon)
18.JCheckBox: setSelected(boolean b)
19.JCheckBox: setSelectedIcon(Icon i)
20.JCheckBox: setText(String text) (HTML)
21.JCheckBox: setToolTipText(String text)