Monday, August 26, 2013


JCheckBoxMenuItem component can used to implement check boxes as the menu items. You can select many checkbox menu items. When you select a check box, menu item displays a check mark. Deselecting the item clears the check mark. Like a menu item, checkbox menu item can display text, icon, and both. Below are constructors that can be used to create a checkbox menu item.

creates a checkbox menu item without text or icon.
-JCheckBoxMenuItem(Action action)
creates a checkbox menu item that its properties are taken from the Action object.
-JCheckBoxMenuItem(Icon icon)
creates a checkbox menu item with the specified icon.
-JCheckBoxMenuItem(String text)
creates a checkbox menu item with the specified text.
-JCheckBoxMenuItem(String text,boolean selected)
creates a checkbox menu item with the specified text and selection state.
-JCheckBoxMenuItem(String text,Icon icon)
creates a checkbox menu item with the specified text and icon.
-JCheckBoxMenuItem(String text,Icon icon,boolean selected)
creates check menu item with the specified text, icon, and selection state.

In the example program below, a menu bar is created using the JMenuBar class. On this menu bar, we place a menu called Format. In the menu Format, there is one checkbox menu item. When the user select this checkbox menu item, the text in the JTextArea will be wrapped.

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

class JCheckBoxMenuItemShow extends JFrame implements ChangeListener{
JTextArea txta;
JCheckBoxMenuItemShow(String title){
setLayout(new FlowLayout());
Container contpane=getContentPane();
contpane.setLayout(new BorderLayout());
JMenuBar mbar=new JMenuBar();
JMenu format=new JMenu("Format");
JCheckBoxMenuItem itemlinewrap=new JCheckBoxMenuItem("Line wrap");
txta=new JTextArea(10,30);
JScrollPane scroll=new JScrollPane(txta);


public void stateChanged(ChangeEvent e){
JCheckBoxMenuItem chm=(JCheckBoxMenuItem)e.getSource();


public class JFrameSwing {
public static void main(String[] args){
new JCheckBoxMenuItemShow("JCheckBoxMenuItem");

JCheckBoxMenuItem Swing


  1. Das Kontrollieren des Kästchens kann ein Problem sein. Wenn du willst, kannst du das machen, ich betway wetten und sie werden dich nicht um eine einzige Frage bitten. Ich habe es ausprobiert und es hat bei mir so oft mit Sicherheit funktioniert.

  2. Thank you, I have recently been looking for info about this subject for ages and yours is the best I have discovered till now. But, what about the bottom line? Are you sure about the source? hearing aids

  3. Hearing Aids Singapore - Visit us for hearing aids in Singapore! Our team can test your hearing and recommend the most suitable hearing aid for your condition.

  4. Receive immediate & long-term suggestions on how to optimize your website. Try it free! Strategy, backlinks, tech SEO, UX, SERP Features, semantics & content ideas. User Experience Ideas. Best Group Buy SEO Tools 2020 Winner. Be in Top 10 of the SERP.