jmenubar

How to make a JMenu have Button behaviour in a JMenuBar

痴心易碎 提交于 2019-12-01 04:41:11
I was trying to make a JMenu behave like a JButton but I'm having some problems and hopefully someone here can help! I've added a MenuListener to the JMenu item with this but I cant get the popup menu/focus to leave to enable me to properly click the JMenu repeated times to trigger this function and i was hoping someone could tell me what i'm doing wrong. Thanks. public void menuSelected(MenuEvent e) { ... // do stuff here code JMenu source = (JMenu)e.getSource(); source.setSelected(false); source.setPopupMenuVisible(false); } Not completely sure what you're asking... But JMenuBar inherits

Swing application menu name not displaying correctly in Java 1.8

对着背影说爱祢 提交于 2019-12-01 03:15:00
问题 Okay, so I've done Swing applications before, and I know if you want to display a different name for the application menu (the one on Macs that usually have a "Preferences" and "Quit" option), you have to use: System.setProperty("com.apple.mrj.application.apple.menu.about.name", "App name"); and it must be executed before the JFrame is created. I've done this, but it continues to show my Main class' name as the menu name, as if I didn't write that line of code at all. I googled for this issue

Why JMenuBar is not place in the JFrame content pane, but JToolbar place in the content pane

↘锁芯ラ 提交于 2019-11-28 14:43:39
Why JMenuBar is not place in the content pane?is there any reason or effects when make a java gui program especially when using jframe? Thanks As stated in Using Top-Level Containers article, the manu bar is managed by the Root Pane: Each top-level container relies on a reclusive intermediate container called the root pane. The root pane manages the content pane and the menu bar, along with a couple of other containers. You generally don't need to know about root panes to use Swing components. However, if you ever need to intercept mouse clicks or paint over multiple components, you should get

Change background and text color of JMenuBar and JMenu objects inside it

放肆的年华 提交于 2019-11-28 00:29:44
How can I set custom background color for JMenuBar and JMenu objects inside it? I tried .setBackgroundColor and it does not work! D180 Create a new class that extends JMenuBar : public class BackgroundMenuBar extends JMenuBar { Color bgColor=Color.WHITE; public void setColor(Color color) { bgColor=color; } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(bgColor); g2d.fillRect(0, 0, getWidth() - 1, getHeight() - 1); } } Now you use this class instead of JMenuBar and set the background color with setColor() . You would

add JMenuBar to a JPanel?

此生再无相见时 提交于 2019-11-27 15:03:40
I've got a JMenuBar and a JPanel. I'd like to add the JMenuBar to the JPanel. How would I do so? You can use a BorderLayout for your JPanel and put the JMenuBar into the NORTH area of the panel with JPanel p = new JPanel(); p.setLayout(new BorderLayout()); p.add(menubar, BorderLayout.NORTH); JMenuBar is a JComponent and can be added to a Container like any other JComponent. JMenuBars are set to the JFrame using the setJMenuBar method. See the following tutorial on how to use them. http://download.oracle.com/javase/tutorial/uiswing/components/menu.html Panday Manish Sahay I tried too but

Change background and text color of JMenuBar and JMenu objects inside it

雨燕双飞 提交于 2019-11-27 04:44:27
问题 How can I set custom background color for JMenuBar and JMenu objects inside it? I tried .setBackgroundColor and it does not work! 回答1: Create a new class that extends JMenuBar : public class BackgroundMenuBar extends JMenuBar { Color bgColor=Color.WHITE; public void setColor(Color color) { bgColor=color; } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(bgColor); g2d.fillRect(0, 0, getWidth() - 1, getHeight() - 1); }

How do I move my JMenuBar to the screen menu bar on Mac OS X?

こ雲淡風輕ζ 提交于 2019-11-26 00:48:56
问题 When I move my JMenuBar to the screen menu bar on Mac OS X, it leaves some blank space where the menu would be in my window; I need to remove that space. I am using System.setProperty(\"apple.laf.useScreenMenuBar\", \"true\") to move my JMenuBar to the screen menu bar. My friend who uses a Mac reports that this leaves some ugly vertical space where the menu would reside if I did not set that property. What is the best way to resolve this issue? EDIT: Here is an example from my source: public