JMenu and JCheckBox

Hi all,
How to select/unselect more than one JCheckBoxMenuItem in a time in a JMenu ?
(for instance i'm not able to select 3 item out of 10 in one time -need to do the manip 3 times ...)
thanks in advance

Ok, i give you an example to be more concrete:
Lets say we have a JMenu with Checkbox giving different movie categories (action, thriller,comedy,western...) .
-> i want to view in my jtable only the categories "action" and "western" by selecting them in the Menu.
-> but as it's currently implemented, once you select one of the category, the JMenu directly auto-closes, so you have once again to open the menu to select the second.
Suppose you have 10 checkbox (out of 20) to select...

Similar Messages

  • JMenu and JMenuItem - Images

    How to put an image in front of the JMenu text?
    JMenuItem has a constructor to insert the icon.
    Is their a reason why it not in the JMenu constructors?
    Sometimes I just want to put a 16 pixel gap in front of the JMenuItem or JMenu if it has no Image. Can one do that without inserting a blank
    Image?
    Thanks

    Have you tried just setting it via setIcon()? Since both JMenu and
    JMenuItem inherit from AbstractButton, this may work; I say may
    since more than likely it is up to the L&F UI to do the right thing.
    A quick browse shows that it ought to work for at least the basic
    L&Fs though.
    As far as the empty gap, looks like you might be out of luck by
    default, but this too is up to the L&F. For instance, some look and
    feels line up the text properly if an item doesn't have an icon.
    As a quick fix, though, you could probably just set the icon to
    something like
    menuItem.setIcon( new Icon() {
        public int getIconWidth() { return 16; }
        public int getIconHeight() { return 0; }
        public void paintIcon(Component c, Graphics g, int x, int y) {}
    });: jay

  • JMenu and Documentation

    Hello friends, couple questions here. Main one i am confused with is the Documentations. I cant quite seem to grasp how to use what they provide. If anyone would be so kind as to take the time and explain to me how to use what the documentation offers i would be grateful.
    http://wwwswt.fzi.de/~jjh/tools/swing/products/jfc/swingdoc-current/api/com.sun.java.swing.JMenuBar.html
    here is a link to a documentation of JMenu and how to make one but i do not get how to apply this into a program. Thank you very much - Jeff

    Specificially, you want this page
    http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html
    This is part of a much bigger tutorial, here
    http://java.sun.com/docs/books/tutorial/
    There are also more tutorials if you click on Tutorials in the upper left of this page.

  • Problem with Alt , JMenu and Mnemonics

    I have built an application with a JMenuBar containing several JMenu's, the first of which is a File menu. All JMenus and JMenuItems have mnemonics associated with them. When I press the alt key the underlines show and focus appears to be given to the File menu (though it has not dropped down). If I then press a key, for example 'S', that is a mnemonic of the 'Save' jmenuitem in the File menu, the Save action is invoked. This should not occur because the menu has not opened yet.
    The behavior is what I'd expect had an accelerator (Alt+S) been defined for the Save menu item. But I have not defined any accelerators.
    Why does this happen and more importantly, is there a work around?

    Except for the 1st line in jbinit() it's all pretty standard stuff. Here's a snippet of the code:
    public class MainFrame extends JFrame implements ChangeListener {
    JMenuBar jMenuBar1 = new JMenuBar();
    JMenu jMenuFile = new JMenu();
    JMenuItem jMenuFileNew = new JMenuItem();
    JMenuItem jMenuFileSave = new JMenuItem();
    JMenu m_editMenu = new JMenu();
    JMenuItem m_editCutMenuItem = new JMenuItem();
    JMenuItem m_editCopyMenuItem = new JMenuItem();
    JMenuItem m_editPasteMenuItem = new JMenuItem();
    public MainFrame() {
    jbInit();
    //Component initialization
    private void jbInit() {
    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
    KeyStroke.getKeyStroke(KeyEvent.VK_ALT, Event.ALT_MASK, false), "repaint");
    // file menu
    jMenuFile.setText("File");
    jMenuFile.setMnemonic(KeyEvent.VK_F);
    jMenuFileNew.setText("New...");
    jMenuFileNew.setMnemonic(KeyEvent.VK_N);
    jMenuFileNew.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jMenuFileNewSpecial_actionPerformed(e);
    jMenuFileSave.setText("Save");
    jMenuFileSave.setMnemonic(KeyEvent.VK_S);
    jMenuFileSave.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jMenuFileSaveSpecial_actionPerformed(e);
    jMenuFile.add(jMenuFileNew);
    jMenuFile.add(jMenuFileSave);
    // edit menu
    m_editMenu.setText("Edit");
    m_editMenu.setMnemonic(KeyEvent.VK_E);
    m_editCutMenuItem.setText("Cut");
    m_editCutMenuItem.setMnemonic(KeyEvent.VK_T);
    m_editCutMenuItem.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    editCutMenuItem_actionPerformed(e);
    m_editCopyMenuItem.setText("Copy");
    m_editCopyMenuItem.setMnemonic(KeyEvent.VK_C);
    m_editPasteMenuItem.setText("Paste");
    m_editPasteMenuItem.setMnemonic(KeyEvent.VK_P);
    m_editMenu.add(m_editCutMenuItem);
    m_editMenu.add(m_editCopyMenuItem);
    m_editMenu.add(m_editPasteMenuItem);
    jMenuBar1.add(jMenuFile);
    jMenuBar1.add(m_editMenu);
    this.setJMenuBar(jMenuBar1);
    etc...
    Pressing Alt+S invokes the action listener for the jMenuFileSave menu item. It should do nothing since there is no top level menu with a mnemonic of 'S'.

  • JMenu and JTabbedPane questions

    Hello I got 2 questions :
    1) Is it possible to change the icon of JMenu when the mouse cursor is on it ? setRolloverIcon function doesnt work in this case, like it does for the JButton.
    2) When I create my application I got 1 JTabbedPane object visible. Now, every time I click a selected JMenuItem, I wanna add another JTabbedPane object to the window. So in the class MyMenu I got this code in actionListener:
    if(arg.equals("menu1")) {
         JTabbedPane tabbedPane = new JTabbedPane();
         tabbedPane.addTab("tab", null, null, "nothing");
         frame.getContentPane().add(tabbedPane);
    The problem is that it doesnt appear on the window, but instead when I resize it, there is a vertical line in the place where the right "edge" of the old window was.
    Can anyone tell me what do I do wrong ?
    Thx in advance.

    Actually I dont know but the simpliest way seems to be subclassing the menu Item, and listen for mouse events. When you learn a better way to do it you can change your code :)
    Java always allowed me to do such tricks :)

  • JMenu and Paint Problem

    Hello,
    I have been teaching my self Java and I have become quite proficient with it, however, I have a problem that I can not fix, or get around.
    I have a JMenuBar in a JFrame with some JMenu�s containing JMenuItems. I also have a JPanel that I draw inside (I Know that is probably not the wisest way to draw things, but it was the way I first learned to draw and now my program is too big and it is not worth while to change). Any ways, I draw some graphics inside of this JPanel.
    The menu items change the drawings; this is done by repainting the JPanel Graphic. However, when I click one of the menu items, the JPanel paints but there is a residual of the JMenu in the background that will not disappear.
    The menu is closed and if I open and then close the menu the residual goes away.
    => I would like to know how to prevent the residual from appearing?
    The problem also occurs when I use the popup menus outside of the JmenuBar.
    What I think is wrong.
    I think my problem is with the repaint. I don�t think the JFrame is repainting. I think I am simply repainting all the components in the JFrame but not the JFrame itself and thus the residual is not cleared from the JFrame. I don�t know how to fix this but I believe that is the problem because when I minimize the JFrame then Maximize it the JFrame will not paint, and I can see right through the JFrame, but the components paint fine.
    Sorry for the long question, but I don�t know what would be helpful.
    Any advice would be appreciated,
    Thank you
    Seraj

    // This is the code that listens for the menu item
    private void RBmmActionPerformed(java.awt.event.ActionEvent evt) {                                    
            calc.setIN(false);
            updateData();                    // updates some data
            paint2();                           // my special draw fuction shown below
        public void paint2()                          // this the special paint that draws on the JPanel
            Graphics page = jPanel1.getGraphics();
            if(start_end)
                myPic.draw(page);
            else
                page.setColor(Color.WHITE);
                page.fillRect((int)(OFFSET.getX()), (int)(OFFSET.getY()), (int)(R_BOUND-OFFSET.getX()), (int)(L_BOUND-OFFSET.getY()));
            repaint();             
    public void paint(Graphics g)               // this is the regular paint methode
            MessageHandler();
            ATD_age.repaint();
            StanderdCal.repaint();
            ChildSRF.repaint();
            MessageArea.repaint();
        }I hope that is helpful

  • AbstractAction and JCheckBox

    Hello,
    I'm using AbstractAction throughout my application, so that I can assign the same action to different components (menu, normal buttons etc.).
    Now I want to create a customized AbstractAction which also handles the selected state of JCheckBox, JMenuItemCheckBox, so that if one CheckBox is selected all CheckBoxes using the same Action is also selected. I thought of using AbstractAction.firePropertyChange, but I am not sure what property to use, and if it will work at all. I want to avoid an infinite recursion.
    Any suggestions?

    Take a look at JGoodies Binding library. Don't reinvent the wheel!!

  • JMenu and JList

    I want to hava a menu that would have some of the same functionality as a JList, such as the cell renderer, the borders and the list models. I'm working inside a JApplet so creating JPopupMenus are out because of it seems to open new Windows in browsers and has that ugly Applet Window warning.
    I want to open pop up menus over the list elements.
    For example, I have a JList that holds user names for a chat room. When an element in that JList is clicked I want to open a menu that lists commands like "go to users homepage", "private chat", "kick out", etc.
    I've written an applet that uses JMenus. But I'd like to have the user list remain a JList because my applet uses the ListModel to pass the list's content to different parts of the program.
    I'd like to have similar functionality to the following (but with a JList instead of a JMenuBar holding the contents of the list)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MenuTestApplet extends JApplet{
    JPanel p = new JPanel(new BorderLayout());
    JMenuBar menuBar = new JMenuBar();
    JScrollPane scroll;
    public MenuTestApplet(){
         getContentPane().add(p, BorderLayout.CENTER);
         menuBar.setBackground(Color.blue.brighter().brighter());
         menuBar.setLayout(new BoxLayout(menuBar, BoxLayout.Y_AXIS));
         for (int i=1; i<50;i++){
         addNewMenu("Menu "+i);
         p.add(new JLabel("nothing here"), BorderLayout.CENTER);
         scroll = new JScrollPane(menuBar);
         p.add(scroll, BorderLayout.CENTER);
    public void addNewMenu(String title){
         JMenu m = new JMenu(title);
         m.setBackground(Color.blue.brighter());
         JMenuItem item = new JMenuItem("one");
         item.setBackground(Color.blue.brighter());
         m.add(item);
         item = new JMenuItem("two");
         item.setBackground(Color.blue.brighter());
         m.add(item);
         item = new JMenuItem("THR33");
         item.setBackground(Color.blue.brighter());
         m.add(item);     
         m.setMinimumSize(m.getPreferredSize());
         m.setMenuLocation(7, 3);
         menuBar.add(m);
    I'm just looking for ideas right now.
    thanks

    would simply adding JMenu's to the JList do the trick?
    this was suggested by someone to me, but I thought that the elements in the JList are simply painted panels that use the objects toString() in the CellRenderer.

  • JMenu and making the popup always visible

    hi,
    i need to keep the menu's popup visible always and eventually the selection of an item even when the focus moves to another component-a text field nearby for example.can this (and how if it is) be achieved or it is totally up to the look and feel and i can't do much about it?
    thank you.

    just for the record,it seems it actually is doable.at least i have a prototype working.it involves removing default mouse listeners from jmenu i jmenuitem and installing "custom" ones that manage the transition of the menu from one state to another.

  • JMenu and About Boxes

    Hi Guys,
    I'm making a small program in Java for a Uni project and part of the specification is that the user should be able to select an 'About This Application' option from the menu bar which shows up asmal dialog box with some text and an OK button to close the box, but I'm not sure how to code this. So far I have...
    menuBar = new JMenuBar();
         menuEdit = new JMenu("Edit"); //shows the menu item Edit.
         menuEdit.setFont(fontMenu);
         menuView = new JMenu("View"); //shows the menu item View.
         menuView.setFont(fontMenu);
         menuHelp = new JMenu("Help"); //shows the menu item Help.
         menuHelp.setFont(fontMenu);
         menuBar.add(menuEdit); //adds menu item "Edit" to the menu bar
         menuBar.add(menuView); //adds menu item "View" to the menu bar
         menuBar.add(menuHelp); //adds menu item "Help" to the menu bar
         setJMenuBar(menuBar);
    I was wondering if anybody could suggest how I can add to this code so that the user can then click on Help in the menu bar, select 'About this application' and on doing so a dialog box pops up with some text information and the OK button.
    Any help appreciated I'm in a bit of a fix here!
    Thanks!

    As a push in the right direction, look to use JOptionPane for creating simple dialogs. (dialog tutorial)

  • JMenu and doClick

    Hi;
    I have a class named as IntelliMenu which extends JMenu. I added speech recognition ability to the JMenu. However when the user says the action command of the menu ( for example "File") I can not make the menu items of this menu visible. Below is the code that I am using. Can you tell me what is wrong with the code? The interesting point is that it sometimes work and sometimes not.
    menu.doClick();
    menu.repaint();  //tried without this line too
    menu.validate();  //tried without this line too

    no relation with speech recognition.Then why did your question mention you where using speech recognition? Don't confuse the problem.
    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html]How to Use Menus.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • JMenu and GridBagConstraints

    how do i add a JMenu item into a gridbagconstraints layout??

    how do a position a JMenu item to the top left corner using GRIDBAGLAYOUT It doesn't change my answer. It doesn't make sense that you are using a GridBagLayout for a JMenu. JMenu is designed to be added to a JMenuBar.
    Do some work on your own and post the code when you have a problem.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • JMenu and MouseListener problems

    I have a JMenu that is used as a JMenuItem in another JMenu in the menu bar. The same JMenu is added as a popup menu to a button.
    I added a MouseListener to the JMenu because I want to execute some code upon mouseEntered() and mouseExited().
    Problem: the listener is only fired when I enter or exit the menu from the menu bar, never when the popup menu of the button is entered or exited.
    What can I do to trigger the mouse listener?

    I have a JMenu that is used as a JMenuItem in another JMenu in the menu bar.Components can only have a single parent. I don't know how what you are describing is possible.
    If you want to share the ActionEvent then you should be using an Action when creating the menu. Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/misc/action.html]How to use Actions.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • JMenu and JTabbedPane

    Hi,
    I'm trying to create different JMenu depending on which tabbedpane you choose.
    Any ideas how to do this???

    add a change listener to the tabbed pane and when it fires, get the selected tab index and update your menus accordingly.

  • Custom text for JMenu and JMenuItem

    hey guys
    right now i can do a :
    JMenu menu = new JMenu("File");but how can i customize the text on the Menu a.k.a "file" so may be it looks bigger or a different color ?
    ive looked at the API i can see that JMenu takes "Action" object too which describes the look. I know Action is an interface and i havent been able to find a suitable class that implements this interface
    so how should i go about changing the text look/feel ?
    thank in advance

    so may be it looks bigger or a different color ?Read the API. There are many different set??? methods which allow you to change the properties of the component including the font size and color of the text.
    i can see that JMenu takes "Action" object too which describes the look.The Action has nothing to do with the look (other then providing the text to display). It has to do with the Action that happens when you select the menu item.

Maybe you are looking for