jmenuitem

Change menu bar and menu items font

柔情痞子 提交于 2019-12-02 10:37:42
I'm trying to make the menu bar items and the items of the items bigger and smaller, I've seached here a bit before (so don't mark this as repeated please) and none of the posts I've found are working. I've tried the following codes without success: Font f = new Font("sans-serif", Font.PLAIN, 12); UIManager.put("menuBar.font", f); And menuBar.setFont(new Font(menuBar.getFont().getFontName(), menuBar.getFont().getStyle(), 12)); And this is my code where I'm trying to edit the font: private class foo{ private JMenu mnArchivo; private JMenuBar menuBar; menuBar = new JMenuBar();

JMenuBar SelectionModel ChangeListener only fires once

时光毁灭记忆、已成空白 提交于 2019-12-02 07:22:05
问题 I am trying to get my JMenuBar to model the behavior of the menu bars of Firefox and iTunes. The behavior: the menu bar is initially hidden. But, when you press Alt , the menu bar appears (with the first item selected) and when you don't have a menu item selected, the menu bar disappears. My idea was to listen for selection changes to the JMenuBar via a ChangeListener on its SelectionModel . However, the behavior of the attached SSCCE is not as desired. When the frame loads, the JMenuBar is

How to make shortcut to invisible menu item in Java

大城市里の小女人 提交于 2019-12-02 04:14:12
I've recently added a console dialog to my program to make catching bugs easier. This is currently accessible through a JMenuItem and has keyboard shortcut 'Ctrl+L'. Ideally I'd like to keep this option in but make the menu item hidden/invisible, because I only really want people to use it if they are copying the contents to me so I can investigate something. However, when I set the menu item to be invisible the shortcut also stops working. Here's what I've tried: mntmViewLogs.setAccelerator(KeyStroke.getKeyStroke('L', KeyEvent.CTRL_DOWN_MASK)); mntmViewLogs.setVisible(false); Thanks! You

JMenuBar SelectionModel ChangeListener only fires once

心不动则不痛 提交于 2019-12-01 23:28:25
I am trying to get my JMenuBar to model the behavior of the menu bars of Firefox and iTunes. The behavior: the menu bar is initially hidden. But, when you press Alt , the menu bar appears (with the first item selected) and when you don't have a menu item selected, the menu bar disappears. My idea was to listen for selection changes to the JMenuBar via a ChangeListener on its SelectionModel . However, the behavior of the attached SSCCE is not as desired. When the frame loads, the JMenuBar is not visible. When you press Alt , the menu bar appears with the first menu selected (thanks to the

Align icon and JCheckbox in JPopupmenu

僤鯓⒐⒋嵵緔 提交于 2019-12-01 20:12:08
I have a Problem with some icons and check-boxes in a JPopupMenu . The Check-boxes and Icons are not aligned The Items are created like: JMenuItem deleteAttributeMenuItem = new JMenuItem(locale.getString("TREE_AttrDelete"), iconDelete); JMenuItem primaryKeyAttributeMenuItem = new JCheckBoxMenuItem(locale.getString("TREE_AttrChkBoxPK")); Please take a look at the picture: Any tips? Have a look at this, in order to achieve what you wanted, I did this, JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem("Check Me", null, true); cbmi.setMargin(new java.awt.Insets(5, 25, 5, 5)); cbmi.setIconTextGap(15);

Custom JMenuItems in Java

烂漫一生 提交于 2019-11-30 07:01:10
Would it be possible to create a custom JMenuItem that contains buttons? For example would it be possible to create a JMenuITem with an item similar to this: +----------------------------------------+ | JMenuItem [ Button | Button | Button ] | +----------------------------------------+ I doubt there is an easy way to do this. You can do something like: JMenuItem item = new JMenuItem("Edit "); item.setLayout( new FlowLayout(FlowLayout.RIGHT, 5, 0) ); JButton copy = new JButton("Copy"); copy.setMargin(new Insets(0, 2, 0, 2) ); item.add( copy ); menu.add( item ); But there are several problems: a

Java Swing OSX Window Menu Icon Alignment

泪湿孤枕 提交于 2019-11-28 14:36:45
Java Swing seems to place the 'Menu Text' after the icon (if present) on MenuItems. See example below. It does NOT look very nice. Is there a way around this? On OSX the icon fits in the left margin and the text aligns with all other MenuItems. Do you mean something like this : import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JTextPaneExample { private Icon info = UIManager.getIcon("OptionPane.informationIcon"); private Icon error = UIManager.getIcon("OptionPane.errorIcon"); private void createAndDisplayGUI() { JFrame frame = new JFrame("JTextPane Example"); frame

Why my ChangeListener reacts only for JMenu, and not for JMenuItem?

流过昼夜 提交于 2019-11-28 04:48:46
问题 Now, I have a JMenu, and some JMenuItems in it. I want my program to perform some action when JMenu's and JMenuItem's state is changed to "selected". I don't use MouseLitener's MouseOver, because I want user to be able to navigate in menu using keyboards too. Now, I wrote this listener: class MenuItemListener implements ChangeListener { @Override public void stateChanged(ChangeEvent arg0) { JMenuItem item = (JMenuItem) arg0.getSource(); if(item.isSelected()) System.out.println(item.getText()+