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

The following examples show how to use javax.swing.JMenuItem#setFont() . 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: DataToolTab.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected javax.swing.JPopupMenu getHorzVariablesPopup() {
  if(varPopup==null) {
    buildVarPopup();
  }
  isHorzVarPopup = true;
  FontSizer.setFonts(varPopup, FontSizer.getLevel());
  for(Component c : varPopup.getComponents()) {
    JMenuItem item = (JMenuItem) c;
    if(xLine.getText().equals(item.getActionCommand())) {
      item.setFont(item.getFont().deriveFont(Font.BOLD));
    } else {
      item.setFont(item.getFont().deriveFont(Font.PLAIN));
    }
  }
  return varPopup;
}
 
Example 2
Source File: OSPCombo.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Shows the popup immediately below the specified field. If item is selected,
 * sets the field text and fires property change.
 *
 * @param field the field that displays the selected string
 */
public void showPopup(final JTextField display) {
  //display = field;
  Action selectAction = new AbstractAction() {
    public void actionPerformed(ActionEvent e) {
      int prev = selected;
      selected = Integer.parseInt(e.getActionCommand());
      display.setText(items[selected]);
      OSPCombo.this.firePropertyChange("index", prev, -1); //$NON-NLS-1$        
    }

  };
  removeAll();
  for(int i = 0; i<items.length; i++) {
    String next = items[i].toString();
    JMenuItem item = new JMenuItem(next);
    item.setFont(display.getFont());
    item.addActionListener(selectAction);
    item.setActionCommand(String.valueOf(i));
    add(item);
  }
  int popupHeight = 8+getComponentCount()*display.getHeight();
  setPopupSize(display.getWidth(), popupHeight);
  show(display, 0, display.getHeight());
}
 
Example 3
Source File: MTabbedPane.java    From javamelody with Apache License 2.0 6 votes vote down vote up
protected JPopupMenu createPopupMenu() {
	final JPopupMenu menu = new JPopupMenu();
	final MenuSelectionHandler menuSelectionHandler = new MenuSelectionHandler();
	final int tabCount = getTabCount();
	final int selectedIndex = getSelectedIndex();
	for (int i = 0; i < tabCount; i++) {
		final JMenuItem menuItem = new JMenuItem(getTitleAt(i), getIconAt(i));
		if (i == selectedIndex) {
			menuItem.setFont(menuItem.getFont().deriveFont(Font.BOLD));
		}
		if (!isEnabledAt(i)) {
			menuItem.setEnabled(false);
		}
		menuItem.setName(String.valueOf(i));
		menuItem.addActionListener(menuSelectionHandler);
		menu.add(menuItem);
	}
	return menu;
}
 
Example 4
Source File: SettingsAction.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void addSoundMenu( JPopupMenu parent ){
	JMenu soundMenu = new JMenu("Sound");
	soundMenu.setFont( TGConfig.FONT_WIDGETS );
	
	JMenuItem soundMixer = new JMenuItem("Open Mixer");
	soundMixer.addActionListener(new TGActionProcessorListener(getContext(), TransportMixerAction.NAME));
	soundMixer.setFont( TGConfig.FONT_WIDGETS );
	soundMenu.add( soundMixer );
	
	JMenuItem soundSetup = new JMenuItem("Sound Settings");
	soundSetup.addActionListener(new TGActionProcessorListener(getContext(), TransportSetupAction.NAME));
	soundSetup.setFont( TGConfig.FONT_WIDGETS );
	soundMenu.add( soundSetup );
	
	parent.add( soundMenu );
}
 
Example 5
Source File: DataToolTab.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected javax.swing.JPopupMenu getVertVariablesPopup() {
  if(varPopup==null) {
    buildVarPopup();
  }
  isHorzVarPopup = false;
  FontSizer.setFonts(varPopup, FontSizer.getLevel());
  for(Component c : varPopup.getComponents()) {
    JMenuItem item = (JMenuItem) c;
    if(yLine.getText().equals(item.getActionCommand())) {
      item.setFont(item.getFont().deriveFont(Font.BOLD));
    } else {
      item.setFont(item.getFont().deriveFont(Font.PLAIN));
    }
  }
  return varPopup;
}
 
Example 6
Source File: SelectTrackAction.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void processAction(TGActionContext context) {
	final AWTEvent awtEvent = context.getAttribute(AWTEvent.class.getName());
	
	final Caret caret = TuxGuitar.instance().getTablatureEditor().getTablature().getCaret();
	final JButton button = (JButton) awtEvent.getSource();
	final JPopupMenu menu = new JPopupMenu();
	Iterator<?> it = TuxGuitar.instance().getTablatureEditor().getTablature().getSong().getTracks();
	while( it.hasNext() ){
		final TGTrack track = (TGTrack) it.next();
		JMenuItem item = new JRadioButtonMenuItem( track.getName() , (track.getNumber() == caret.getTrack().getNumber()) );
		item.setFont( TGConfig.FONT_WIDGETS );
		item.addActionListener( new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				caret.update( track.getNumber() );
				TuxGuitar.instance().updateCache( true );
			}
		});
		menu.add( item );
	}
	menu.show(button, 0, button.getHeight() );
}
 
Example 7
Source File: RecentItems.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
/**
 * Add list orecentProjFile recent projects as Menu Items to the Recent
 * projects menu
 *
 *
 * @param recentProj instance orecentProjFile the menu to address
 * <code>Recent Projects</code>
 */
public void updateMenu(JMenu recentProj) {
    recentProj.removeAll();
    try {
        for (String file : recentProjects) {
            recentItemMenu = new JMenuItem();
            recentItemMenu.setFont(new java.awt.Font("sansserif", 0, 11));
            recentItemMenu.setText(toName(file));
            recentItemMenu.setToolTipText(file);
            recentProj.add(recentItemMenu);
            addlistener(recentItemMenu);
        }
    } catch (Exception ex) {
        Logger.getLogger(RecentItems.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 8
Source File: SettingsPage.java    From xdm with GNU General Public License v2.0 6 votes vote down vote up
private void showMoveQPopup(JButton btn) {
	int index = qList.getSelectedIndex();
	if (index < 0) {
		return;
	}
	DownloadQueue q = queueModel.get(index);
	String qid = q.getQueueId();
	if (qid == null)
		return;
	JPopupMenu popupMenu = new JPopupMenu();
	for (int i = 0; i < QueueManager.getInstance().getQueueList().size(); i++) {
		DownloadQueue tq = QueueManager.getInstance().getQueueList().get(i);
		if (qid.equals(tq.getQueueId())) {
			continue;
		}
		JMenuItem item = new JMenuItem(tq.getName());
		item.setName("Q_MOVE_TO:" + tq.getQueueId());
		item.addActionListener(this);
		item.setForeground(Color.WHITE);
		item.setFont(FontResource.getNormalFont());
		popupMenu.add(item);
	}
	popupMenu.setInvoker(btn);
	popupMenu.show(btn, 0, btn.getHeight());
}
 
Example 9
Source File: CustomCellEditor.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
private TextFieldPopupMenu() {
    final FontData fontData = Display.getCurrent().getSystemFont().getFontData()[0];

    final Font font = new Font(fontData.getName(), Font.PLAIN, 12);

    final JMenuItem cutMenuItem = this.add(new CutAction());
    cutMenuItem.setFont(font);

    final JMenuItem copyMenuItem = this.add(new CopyAction());
    copyMenuItem.setFont(font);

    final JMenuItem pasteMenuItem = this.add(new PasteAction());
    pasteMenuItem.setFont(font);
}
 
Example 10
Source File: CustomCellEditor.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
private TextFieldPopupMenu() {
	FontData fontData = Display.getCurrent().getSystemFont()
			.getFontData()[0];

	Font font = new Font(fontData.getName(), Font.PLAIN, 12);

	JMenuItem cutMenuItem = this.add(new CutAction());
	cutMenuItem.setFont(font);

	JMenuItem copyMenuItem = this.add(new CopyAction());
	copyMenuItem.setFont(font);

	JMenuItem pasteMenuItem = this.add(new PasteAction());
	pasteMenuItem.setFont(font);
}
 
Example 11
Source File: ExplorerContextMenuFactory.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
JPopupMenu createPopupMenu() {
    // Get actions for the node
    List<Action>[] actionsArray = getActions();
    List<Action> defaultActions = actionsArray[0];
    List<Action> actions = actionsArray[1];

    // Return if there are no actions to display
    if (defaultActions.size() == 0 && actions.size() == 0) return null;

    // Create a popup menu
    JPopupMenu popupMenu = new JPopupMenu();

    // Insert default actions
    boolean realDefaultAction = true;
    if (!defaultActions.isEmpty()) {
        for (Action defaultAction : defaultActions) {
            JMenuItem defaultItem = new DataSourceItem(defaultAction);
            if (realDefaultAction) {
                defaultItem.setFont(defaultItem.getFont().deriveFont(Font.BOLD));
                realDefaultAction = false;
            }
            popupMenu.add(defaultItem);
        }
    }

    // Insert separator between default action and other actions
    if (!defaultActions.isEmpty() && !actions.isEmpty()) popupMenu.addSeparator();

    // Insert other actions
    if (!actions.isEmpty()) {
        for (Action action : actions) {
            if (action == null) popupMenu.addSeparator();
            else popupMenu.add(createItem(action));
        }
    }
    
    return popupMenu;
}
 
Example 12
Source File: HeapViewerNodeAction.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void populatePopup(JPopupMenu popup) {
    int lastPosition = -1;
    for (HeapViewerNodeAction action : actions) {
        int position = action.getPosition() / 100;
        if (position > lastPosition && lastPosition != -1) popup.addSeparator();
        JMenuItem mi = new JMenuItem(action);
        if (action.isDefault()) mi.setFont(mi.getFont().deriveFont(Font.BOLD));
        popup.add(mi);
        lastPosition = position;
    }
}
 
Example 13
Source File: MenuFactory.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
private static void setMenuProperties(JMenuItem menuItem) {
	menuItem.setOpaque(false);
	menuItem.setBackground(ColorPalette.DARK_BACKGROUND_COLOR);
	menuItem.setForeground(ColorPalette.FOREGROUND_COLOR);
	menuItem.setFont(Fonts.FONT);
	menuItem.setCursor(Cursors.CURSOR);
}
 
Example 14
Source File: TilePopup.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds an indian settlement entry to this popup.
 *
 * @param is The {@code IndianSettlement} that will be
 *     represented on the popup.
 */
private void addIndianSettlement(final IndianSettlement is) {
    StringTemplate name
        = is.getLocationLabelFor(freeColClient.getMyPlayer());
    JMenuItem menuItem = Utility.localizedMenuItem(name);
    menuItem.setFont(FontLibrary.createFont(FontLibrary.FontType.NORMAL,
        FontLibrary.FontSize.TINY, Font.BOLD,
        gui.getImageLibrary().getScaleFactor()));
    menuItem.addActionListener((ActionEvent ae) -> {
            gui.showIndianSettlement(is);
        });
    add(menuItem);
    hasAnItem = true;
}
 
Example 15
Source File: JCEditor.java    From JCEditor with GNU General Public License v2.0 5 votes vote down vote up
/**
* Método que cria os menus para as funções do programa (copiar, colar, abrir, etc.)
* @param nome String - nome que será dado ao JMenuItem
* @param img String - caminho da imagem PNG do JMenuItem
* @param ev ActionListener - evento que será executado ao pressionar o menu
* @param ac int - accelerator (KeyEvent)
* @param ac2 int - accelerator (ActionEvent)
* @param principal JMenu - menu ao qual o JMenuItem pertence
*/
private JMenuItem configMenu(String nome , String img, ActionListener ev, int ac, int ac2, JMenu principal) {
	JMenuItem itemDeMenu = new JMenuItem(nome);
	itemDeMenu.setIcon(new ImageIcon(getClass().getResource(img)));
	itemDeMenu.addActionListener(ev);
	itemDeMenu.setFont(roboto);
	itemDeMenu.setAccelerator(KeyStroke.getKeyStroke(ac, ac2));
	principal.add(itemDeMenu);

	return itemDeMenu;
}
 
Example 16
Source File: JPlagCreator.java    From jplag with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This method initializes jMenuItem
 * 
 * @return javax.swing.JMenuItem
 */
public static JMenuItem createJMenuItem(String text) {
	JMenuItem jMenuItem = new JMenuItem();
	jMenuItem.setText(text);
	jMenuItem.setFont(JPlagCreator.SYSTEM_FONT);
	jMenuItem.setBackground(JPlagCreator.SYSTEMCOLOR);
	return jMenuItem;
}
 
Example 17
Source File: AbstractMenuCreator.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * Update menuItem style depending on the page attributes.
 * 
 * @param menuItem Menu item.
 * @param page Page.
 */
protected void updateFont(JMenuItem menuItem, Page page) {
  if ((menuItem == null) || (page == null)) {
    return;
  }
  if (page.getRedirects().isRedirect()) {
    menuItem.setFont(menuItem.getFont().deriveFont(redirectAttributes));
  }
  if (Boolean.TRUE.equals(page.isDisambiguationPage())) {
    menuItem.setFont(menuItem.getFont().deriveFont(disambiguationAttributes));
  }
  if (Boolean.FALSE.equals(page.isExisting())) {
    menuItem.setFont(menuItem.getFont().deriveFont(missingAttributes));
  }
}
 
Example 18
Source File: UIRes.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
public static void addPopMenu(final JPopupMenu menu, final String name, final Updateable update) {
	JMenuItem tempMenu = new JMenuItem(name);
	tempMenu.setFont(getFont());
	tempMenu.addActionListener(new ActionListener() {

		@Override
		public void actionPerformed(ActionEvent e) {
			if (update != null) {
				update.action(e);
			}
		}
	});
	menu.add(tempMenu);
}
 
Example 19
Source File: ClientContextMenu.java    From chipster with MIT License 5 votes vote down vote up
public ClientContextMenu(SwingClientApplication application) {
	this.application = application;

	this.addPopupMenuListener(this);

	visualiseMenuItem = new JMenuItem("Visualise");
	visualiseMenuItem.setFont(this.getFont().deriveFont(Font.BOLD));
	metadataLinkMenu = new JMenu("Link to phenodata");
	metadataLinkMenu.setIcon(VisualConstants.getIcon(VisualConstants.LINK_PHENODATA_MENUICON));
	linksMenu = new JMenu("Links between selected");
	linkToMenu = new JMenu("Link");
	linkToMenu.setIcon(VisualConstants.getIcon(VisualConstants.LINK_MENUICON));
	linksMenu.add(linkToMenu);
	unlinkMenu = new JMenu("Unlink");
	unlinkMenu.setIcon(VisualConstants.getIcon(VisualConstants.UNLINK_MENUICON));
	linksMenu.add(unlinkMenu);

	renameMenuItem = new JMenuItem("Rename");
	deleteMenuItem = new JMenuItem("Delete");
	deleteMenuItem.setIcon(VisualConstants.getIcon(VisualConstants.DELETE_MENUICON));
	importMenuItem = new JMenuItem("Import files...");
	exportMenuItem = new JMenuItem("Export...");
	exportMenuItem.setIcon(VisualConstants.getIcon(VisualConstants.EXPORT_MENUICON));
	historyMenuItem = new JMenuItem("View history as text");
	historyMenuItem.setIcon(VisualConstants.getIcon(VisualConstants.GENERATE_HISTORY_ICON));
	saveWorkflowItem = new JMenuItem("Save workflow");
	
	
	visualiseMenuItem.addActionListener(this);
	renameMenuItem.addActionListener(this);
	deleteMenuItem.addActionListener(this);
	importMenuItem.addActionListener(this);
	exportMenuItem.addActionListener(this);
	historyMenuItem.addActionListener(this);
	saveWorkflowItem.addActionListener(this);

}
 
Example 20
Source File: MainFrameMenu.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
JMenuItem createRecentItem(final File f, final SaveType localSaveType) {
    if (MainFrame.GUI2_DEBUG) {
        System.out.println("createRecentItem(" + f + ", " + localSaveType + ")");
    }
    String name = f.getName();

    final JMenuItem item = new JMenuItem(name);
    item.addActionListener(e -> {
        try {
            mainFrame.setCursor(new Cursor(Cursor.WAIT_CURSOR));

            if (!f.exists()) {
                JOptionPane.showMessageDialog(null,
                        L10N.getLocalString("msg.proj_not_found", "This project can no longer be found"));
                GUISaveState.getInstance().fileNotFound(f);
                return;
            }
            GUISaveState.getInstance().fileReused(f);// Move to front in
            // GUISaveState, so
            // it will be last
            // thing to be
            // removed from the
            // list

            recentMenuCache.addRecentFile(f);

            if (!f.exists()) {
                throw new IllegalStateException("User used a recent projects menu item that didn't exist.");
            }

            // Moved this outside of the thread, and above the line
            // saveFile=f.getParentFile()
            // Since if this save goes on in the thread below, there is
            // no way to stop the save from
            // overwriting the files we are about to load.
            if (mainFrame.getCurProject() != null && mainFrame.isProjectChanged()) {
                int response = JOptionPane.showConfirmDialog(mainFrame, L10N.getLocalString("dlg.save_current_changes",
                        "The current project has been changed, Save current changes?"), L10N.getLocalString(
                                "dlg.save_changes", "Save Changes?"), JOptionPane.YES_NO_CANCEL_OPTION,
                        JOptionPane.WARNING_MESSAGE);

                if (response == JOptionPane.YES_OPTION) {
                    if (mainFrame.getSaveFile() != null) {
                        mainFrame.getMainFrameLoadSaveHelper().save();
                    } else {
                        mainFrame.getMainFrameLoadSaveHelper().saveAs();
                    }
                } else if (response == JOptionPane.CANCEL_OPTION) {
                    return;
                    // IF no, do nothing.
                }
            }

            SaveType st = SaveType.forFile(f);
            boolean result = true;
            switch (st) {
            case XML_ANALYSIS:
                result = mainFrame.openAnalysis(f, st);
                break;
            case FBP_FILE:
                result = mainFrame.getMainFrameLoadSaveHelper().openFBPFile(f);
                break;
            case FBA_FILE:
                result = mainFrame.getMainFrameLoadSaveHelper().openFBAFile(f);
                break;
            default:
                mainFrame.error("Wrong file type in recent menu item.");
            }

            if (!result) {
                JOptionPane.showMessageDialog(MainFrame.getInstance(), "There was an error in opening the file",
                        "Recent Menu Opening Error", JOptionPane.WARNING_MESSAGE);
            }
        } finally {
            mainFrame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            mainFrame.setSaveType(localSaveType);
        }
    });
    item.setFont(item.getFont().deriveFont(Driver.getFontSize()));
    return item;
}