jmenuitem

How to setSelected by name some JMenuItem in a JPopUpMenu?

纵然是瞬间 提交于 2019-12-11 05:19:20
问题 I have a JPopUpMenu with several JCheckBoxMenuItem's on it. I also have a properties files (config.properties) where I put a parameter which save every JCheckBoxMenuItem the user has checked on this JPopUpMenu , when i close the application. So this file is like : config.properties : listeFiltres =Autres,Afrique du sud,Algérie What I would like to do is , on the start of my application, to setSelected every item that is saved in my properties parameter. For exemple, if "Afrique,Algérie

Tooltip for a JMenuItem

故事扮演 提交于 2019-12-11 02:37:29
问题 I add a menu to a toolbar like this : JMenuBar menu = new JMenuBar(); JMenu actions = new JMenu("Aktionen"); Icon menuIcon = ImageUtilities.loadImageIcon("pathToIcon", true); actions.setIcon(menuIcon); // Add JMenuItem addItem = new JMenuItem("Add"); Icon addIcon = ImageUtilities.loadImageIcon("pathToIcon", true); addItem.setIcon(addIcon); addItem.setToolTipText("Add new Item"); addItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {

Setting icon in JMenuItem makes menu text match icon color

杀马特。学长 韩版系。学妹 提交于 2019-12-10 20:25:38
问题 When adding a menu item (whether hard-coded as in my example below or with an Action), the color of the icon causes the color of the text of the menu item to change. This is strange and, in the case of a white or very light icon, can cause the menu item to be unreadable. How do I turn this off? Calling setForeground(Color.black) on the menu item does not work. SSCCE: import javax.swing.*; import java.awt.*; public class Test extends JFrame { public Test() { JMenuBar bar = new JMenuBar();

How to remove the border on a JMenu or JMenuItem

我只是一个虾纸丫 提交于 2019-12-10 18:34:09
问题 I'm using Eclipse Luna with Java 1.7 and am trying to create a JPanel that has a JMenuBar . This JMenuBar contains a JMenu which again contains a JMenuItem . To fit the whole JMenuBar into my project's visual design, I changed the background and foreground colors of JMenu , JMenuBar and JMenuItem using UIManager.put() . The result should be a drop-down menu with sections only divided by different shades of a Color (blue in my example). No lines or borders. However, a whiteish, silverish

how to get the name of a JMenu when a JMenuItem is clicked

依然范特西╮ 提交于 2019-12-10 11:45:34
问题 How would one get the name of the JMenu holding a clicked JMenuItem? I tried doing this: public void actionPerformed(ActionEvent arg0) { JMenu menuthing = (JMenu)(arg0.getSource()); String menuString = menuthing.getText(); JMenuItem source = (JMenuItem)(arg0.getSource()); String colorType = source.getText(); But it gives me this error: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JMenuItem cannot be cast to javax.swing.JMenu So is there a way to cast to

JMenuItem shows checkbox on the left, how to disable it?

浪尽此生 提交于 2019-12-08 11:37:52
问题 I'm building a drop down menu which resides in program menu bar and pops up a JPopupMenu if a JButton gets clicked. In the JPopupMenu there are multiple JMenuItems. However, beside every JMenuItem it shows a checkbox! Which looks like this: I don't think it should, and there is explicit JCheckBoxMenuItem for that. Does anyone know why a check box appears in a JMenuItem and how do I disable / remove it? The code ImageIcon icon = ViewUtilities.createIcon("resource/gui/mainMenu.png",

How to set a size for JMenuItem?

蹲街弑〆低调 提交于 2019-12-07 15:29:36
问题 As you can see, it's ugly to have these kind of JMenuItem s. The width of the menu items is quite small. Here is the code: JMenu menuOne=new JMenu("MenuOne"); JMenu menuTwo=new JMenu("MenuTwo"); JMenu menuThree=new JMenu("MenuThree"); JMenu menuFour=new JMenu("MenuFour"); JMenuBar mbar=new JMenuBar(); //add the menu to menubar mbar.add(menuOne); JMenuItem OneItOne=new JMenuItem("1"); JMenuItem OneItTwo=new JMenuItem("2"); menuOne.add(OneItOne); menuOne.addSeparator(); menuOne.add(OneItTwo);

Java Swing - Add leniency when selecting items in submenus

送分小仙女□ 提交于 2019-12-07 03:05:30
问题 When attempting to click on an item in a submenu, it is natural to quickly draw your mouse across the menu items below it. Both Windows and Mac natively handle this by putting a small delay before the a menu is opened. Swing JMenus do not handle this, and the menu the mouse briefly hovers over would be opened before the mouse reaches the intended menu item. For example, in the image below, if I tried to select Item 3 , but in the process my mouse briefly slid across Menu 2 , the Menu 1

JMenuItems painting over higher components in JLayeredPane

筅森魡賤 提交于 2019-12-06 08:01:09
问题 I have a set of JMenuItems in a JPanel on one layer of a JLayeredPane, and an emulated cursor painted in a JPanel on a higher layer. When the menu items repaint, they paint over the emulated cursor (without triggering a repaint of the cursor layer). Interestingly, if I substitute JButtons or JLabels for the menu items, the cursor is correctly painted each time the menu items repaint. How can I ensure that repainting the menu items will cause the affected regions of the higher layers to

How I can change JMenuItem alignment to right align

六月ゝ 毕业季﹏ 提交于 2019-12-06 02:08:00
问题 I have written a program in java with netBeans editor. my form have a jmenuBar with some jmenu in right alignment. for example jmenu1 have some jmenuItem , i want right align all jmenuitem 's text. when i change Horizontal alignment of them to right, text not shown when i run it. menuItem1.setHorizontalAlignment(SwingConstants.RIGHT); How i can do it? http://upcity.ir/images/18431917276667197781.jpg 回答1: JMenuItem item1 = new JMenuItem("Item 1"); JMenuItem item2 = new JMenuItem("Item ________