use of javax.swing.JCheckBoxMenuItem in project jdk8u_jdk by JetBrains.
the class bug6438430 method main.
public static void main(String[] args) {
JMenu subMenu1 = new JMenu("Long-titled Sub Menu");
subMenu1.add(new JMenuItem("SubMenu Item"));
JMenuItem checkBoxMenuItem1 = new JCheckBoxMenuItem("CheckBox");
JMenu menu1 = new JMenu("It works always");
menu1.add(checkBoxMenuItem1);
menu1.add(subMenu1);
// Simulate DefaultMenuLayout calls.
// The latest traversed menu item must be the widest.
checkBoxMenuItem1.getPreferredSize();
int width1 = subMenu1.getPreferredSize().width;
System.out.println("width1 = " + width1);
JMenu subMenu2 = new JMenu("Long-titled Sub Menu");
subMenu2.add(new JMenuItem("SubMenu Item"));
JMenuItem checkBoxMenuItem2 = new JCheckBoxMenuItem("CheckBox");
JMenu menu2 = new JMenu("It did not work before the fix");
menu2.add(subMenu2);
menu2.add(checkBoxMenuItem2);
// Simulate DefaultMenuLayout calls.
// The latest traversed menu item must be the widest.
subMenu2.getPreferredSize();
int width2 = checkBoxMenuItem2.getPreferredSize().width;
System.out.println("width2 = " + width2);
if (width1 != width2) {
throw new RuntimeException("Submenu title and submenu indicator " + "overlap on JMenuItem!");
}
System.out.println("Test passed");
}
use of javax.swing.JCheckBoxMenuItem in project JMRI by JMRI.
the class RpsPositionIcon method showPopUp.
/**
* Pop-up contents
*/
@Override
public boolean showPopUp(JPopupMenu popup) {
if (showIdItem == null) {
showIdItem = new JCheckBoxMenuItem("Show ID");
showIdItem.setSelected(false);
showIdItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
toggleID(showIdItem.isSelected());
}
});
}
popup.add(showIdItem);
popup.add(new AbstractAction("Set Origin") {
@Override
public void actionPerformed(ActionEvent e) {
setRpsOrigin();
}
});
popup.add(new AbstractAction("Set Current Location") {
@Override
public void actionPerformed(ActionEvent e) {
setRpsCurrentLocation();
}
});
notify = new Notifier();
popup.add(notify);
popup.add(new AbstractAction("Set Filter") {
@Override
public void actionPerformed(ActionEvent e) {
setFilterPopup();
}
});
// add help item
JMenuItem item = new JMenuItem("Help");
jmri.util.HelpUtil.addHelpToComponent(item, "package.jmri.jmrit.display.RpsIcon");
popup.add(item);
// update position
notify.setPosition(getX(), getY());
return false;
}
use of javax.swing.JCheckBoxMenuItem in project JMRI by JMRI.
the class BeanTableDataModel method showTableHeaderPopup.
protected void showTableHeaderPopup(MouseEvent e, JTable table) {
JPopupMenu popupMenu = new JPopupMenu();
XTableColumnModel tcm = (XTableColumnModel) table.getColumnModel();
for (int i = 0; i < tcm.getColumnCount(false); i++) {
TableColumn tc = tcm.getColumnByModelIndex(i);
String columnName = table.getModel().getColumnName(i);
if (columnName != null && !columnName.equals("")) {
JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(table.getModel().getColumnName(i), tcm.isColumnVisible(tc));
menuItem.addActionListener(new headerActionListener(tc, tcm));
popupMenu.add(menuItem);
}
}
popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
use of javax.swing.JCheckBoxMenuItem in project JMRI by JMRI.
the class PanelEditor method setMultiItemsPositionableMenu.
// This adds a single CheckBox in the PopupMenu to set or clear all the selected
// items "Lock Position" or Positionable setting, when clicked, all the items in
// the selection will be changed accordingly.
private void setMultiItemsPositionableMenu(JPopupMenu popup) {
// This would do great with a "greyed" CheckBox if the multiple items have different states.
// Then selecting the true or false state would force all to change to true or false
JCheckBoxMenuItem lockItem = new JCheckBoxMenuItem(Bundle.getMessage("LockPosition"));
// used to decide the state of the checkbox shown
boolean allSetToMove = false;
// used to see if all items have the same setting
int trues = 0;
int size = _selectionGroup.size();
for (int i = 0; i < size; i++) {
Positionable comp = _selectionGroup.get(i);
if (!comp.isPositionable()) {
allSetToMove = true;
trues++;
}
lockItem.setSelected(allSetToMove);
lockItem.addActionListener(new ActionListener() {
Positionable comp;
JCheckBoxMenuItem checkBox;
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
comp.setPositionable(!checkBox.isSelected());
setSelectionsPositionable(!checkBox.isSelected(), comp);
}
ActionListener init(Positionable pos, JCheckBoxMenuItem cb) {
comp = pos;
checkBox = cb;
return this;
}
}.init(comp, lockItem));
}
// until we get a "greyed" CheckBox ;) - GJM
if ((trues != size) && (trues != 0)) {
lockItem.setText("~ " + lockItem.getText());
// uncheck box if all not the same
lockItem.setSelected(false);
}
popup.add(lockItem);
}
use of javax.swing.JCheckBoxMenuItem in project JMRI by JMRI.
the class Editor method setPositionableMenu.
/*
* *********************** Popup Item Methods **********************
*
*
* These methods are to be called from the editor view's showPopUp method
*/
/**
* Add a checkbox to lock the position of the Positionable item
*
* @param p the item
* @param popup the menu to add the lock menu item to
*/
public void setPositionableMenu(Positionable p, JPopupMenu popup) {
JCheckBoxMenuItem lockItem = new JCheckBoxMenuItem(Bundle.getMessage("LockPosition"));
lockItem.setSelected(!p.isPositionable());
lockItem.addActionListener(new ActionListener() {
Positionable comp;
JCheckBoxMenuItem checkBox;
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
comp.setPositionable(!checkBox.isSelected());
setSelectionsPositionable(!checkBox.isSelected(), comp);
}
ActionListener init(Positionable pos, JCheckBoxMenuItem cb) {
comp = pos;
checkBox = cb;
return this;
}
}.init(p, lockItem));
popup.add(lockItem);
}
Aggregations