Note that there are some explanatory texts on larger screens.

plurals
  1. POSwing: link toggle buttons together with a button group, along with corresponding menu items
    primarykey
    data
    text
    <p>For a school project, I need to make a simple paint application that can draw lines, ovals, and rectangles.</p> <p>The assignment specifies that I need toolbar buttons <em>and</em> menu items for each type of shape.</p> <p>I would like to go a little above and beyond, by making the buttons <code>JToggleButtons</code> in the toolbar and the menu items <code>JRadioButtonMenuItems</code>. Furthermore, I want it so that when you select one of the toolbar buttons, it deselects the other ones, selects the appropriate menu item, and deselects the other menu items. Same for selecting one of the menu items.</p> <p>I know I can group any <code>AbstractButton</code> with a <code>ButtonGroup</code>, but I am not sure if this is the right way to go, because though it handles one "group" of buttons just fine, I am not sure it can handle two parallel groups.</p> <p>Doing it without <code>ButtonGroup</code> would mean in each of the 6 event listeners I would have to manually deselect the other buttons, and each pair would call the same code to set the shape type.</p> <p>I could also make two <code>ButtonGroup</code>s, one for the menu, one for the toolbar, but then I also have to duplicate shape type setting code.</p> <p>In either situation, I also run the risk of the menu setting a button which sets a menu item which sets a button, ad infintum.</p> <p>What is the best way to tackle this problem?</p> <p>(Bonus points for being able to solve the problem with the Netbeans GUI designer; It's just easier)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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