jmenu

JMenu submenu little arrow icon indicator

假如想象 提交于 2019-12-02 16:09:37
问题 Does anyone know how to control the display of the tiny little arrow that appears on submenus of JMenu? Can I change it? Can I disable it? Can I move it? Also, I notice that this arrow doesn't appear on top level JMenus only when they are submenus of other JMenu. This inconsistency annoys me since I have a mix of JMenuItem and JMenu attached to the root of my JMenuBar and so I wish it would always indicate it. Anyway to do this as well? thanks! 回答1: Take a look at the Menu.arrowIcon UI

JMenu submenu little arrow icon indicator

早过忘川 提交于 2019-12-02 09:56:17
Does anyone know how to control the display of the tiny little arrow that appears on submenus of JMenu? Can I change it? Can I disable it? Can I move it? Also, I notice that this arrow doesn't appear on top level JMenus only when they are submenus of other JMenu. This inconsistency annoys me since I have a mix of JMenuItem and JMenu attached to the root of my JMenuBar and so I wish it would always indicate it. Anyway to do this as well? thanks! Take a look at the Menu.arrowIcon UI property (Thanks to AndrewThompson for the test code). Doining this will effect ALL the menus created AFTER you

Making a JButton act like a JMenu

好久不见. 提交于 2019-12-01 14:52:08
I have the following code for a JMenuBar (This code has been taken from a free java program call JGuiD and edited for personal purposes) import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; import java.awt.Dimension; import java.awt.Color; public class GuiDMenuBar extends JMenuBar { JMenu m_file,m_edit,m_help; JMenuItem mi_f_new,mi_f_open,mi_f_save,mi_f_saveas,mi_f_exit; JMenuItem mi_e_cut,mi_e_copy,mi_e_paste,mi_e_delete; JMenuItem mi_v_motif,mi_v_java,mi_v_windows,mi_v_nimbus; JMenuItem mi_h_help,mi_h_about; JButton m_code; public GuiDMenuBar() { setBorderPainted(true);

Making a JButton act like a JMenu

别说谁变了你拦得住时间么 提交于 2019-12-01 12:10:13
问题 I have the following code for a JMenuBar (This code has been taken from a free java program call JGuiD and edited for personal purposes) import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; import java.awt.Dimension; import java.awt.Color; public class GuiDMenuBar extends JMenuBar { JMenu m_file,m_edit,m_help; JMenuItem mi_f_new,mi_f_open,mi_f_save,mi_f_saveas,mi_f_exit; JMenuItem mi_e_cut,mi_e_copy,mi_e_paste,mi_e_delete; JMenuItem mi_v_motif,mi_v_java,mi_v_windows,mi_v

JMenu consumes focuslost event in Windows7 LAF Java7

▼魔方 西西 提交于 2019-12-01 11:36:57
If a popup menu is still open when another component is clicked, then the component does not get the event, because it's probably consumed by the popup. This happens for all JPopupmenus in general. This happens only in Java 7 with windows LAF (Windows7). Is there a workaround? Is it a known bug? import javax.swing.*; import java.awt.event.*; public class Test { public static void main(String[] s) throws Exception { String lookAnfFeelClassName = UIManager.getSystemLookAndFeelClassName(); UIManager.setLookAndFeel(lookAnfFeelClassName); JMenu menu = new JMenu("TEST Menu"); JMenuItem menuItem =

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

Why isn't JMenu always on top?

≯℡__Kan透↙ 提交于 2019-12-01 02:10:14
The JMenu behaves normally until a JButton is used to update a JTable on the JFrame. Then the JMenu is mostly hidden by a JPanel (see images below). Shouldn't the JMenu always be on top when it is selected? Why has it been pushed to the back? The code that updates the table on jButtonAddActionPerformed is. public class MyClass extends javax.swing.JFrame { private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) { DefaultTableModel model = (DefaultTableModel) jTable.getModel(); model.addRow(new Object[]{"", DEFAULT_ON, DEFAULT_OFF}); int lastRow = jTable.getRowCount() - 1; jTable

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

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()+

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