Java Code Examples for javax.swing.JMenuItem#setPreferredSize()

The following examples show how to use javax.swing.JMenuItem#setPreferredSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PerspectiveMenuToggleButton.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Adds the new perspective action to the menu.
 */
private void addNewPerspectiveAction() {
	Action newPerspectiveAction = new NewPerspectiveAction();
	newPerspectiveAction.putValue(Action.LARGE_ICON_KEY, null);
	newPerspectiveAction.putValue(Action.SMALL_ICON, null);

	JMenuItem item = new JMenuItem(newPerspectiveAction);
	item.setPreferredSize(new Dimension(item.getPreferredSize().width + 30, item.getPreferredSize().height));

	popupMenu.addSeparator();
	popupMenu.add(item);
	popupMenu.addSeparator();
}
 
Example 2
Source File: DropDownMenuEditor.java    From jaamsim with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {

	if ("button".equals(e.getActionCommand())) {

		String valStr = input.getValueString();
		ScrollablePopupMenu menu = new ScrollablePopupMenu();
		Component button = (Component)e.getSource();
		Component panel = button.getParent();
		for (final String option : options) {
			JMenuItem item = new JMenuItem(option);
			item.setPreferredSize(panel.getPreferredSize());
			item.addActionListener( new ActionListener() {

				@Override
				public void actionPerformed( ActionEvent event ) {
					setValue(option);
					stopCellEditing();
					propTable.requestFocusInWindow();
				}
			} );
			menu.add(item);
		}
		menu.show(panel, 0, panel.getHeight());

		// Scroll to show the present value
		if (input.isDefault())
			return;
		int index = options.indexOf(valStr);
		if (index != -1) {
			menu.ensureIndexIsVisible(index);
		}
		return;
	}
}
 
Example 3
Source File: ExpressionEditor.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {

	if ("button".equals(e.getActionCommand())) {

		// Launch the Expression Builder if there are no other options
		ArrayList<String> array = input.getValidOptions(EditBox.getInstance().getCurrentEntity());
		if (array == null || array.isEmpty()) {
			launchExpressionBox();
			return;
		}

		// If there are multiple options, select either one of the options or the
		// Expression Builder
		String valStr = input.getValueString();
		final String expBuilderOption = String.format("*** %s ***", ExpressionBox.DIALOG_NAME);
		array.add(0, expBuilderOption);
		ScrollablePopupMenu menu = new ScrollablePopupMenu();
		Component button = (Component)e.getSource();
		Component panel = button.getParent();
		for (final String option : array) {
			JMenuItem item = new JMenuItem(option);
			if (option.equals(valStr)) {
				item.setArmed(true);
			}
			item.setPreferredSize(panel.getPreferredSize());
			item.addActionListener( new ActionListener() {

				@Override
				public void actionPerformed( ActionEvent event ) {
					if (expBuilderOption.equals(option)) {
						launchExpressionBox();
						return;
					}
					setValue(option);
					stopCellEditing();
					propTable.requestFocusInWindow();
				}
			} );
			menu.add(item);
		}
		menu.show(panel, 0, panel.getHeight());

		// Scroll to show the present value
		if (input.isDefault())
			return;
		int index = array.indexOf(valStr);
		if (index != -1) {
			menu.ensureIndexIsVisible(index);
		}
		return;
	}
}