Tag: jmenubar

更改菜单栏和菜单项字体

我正在尝试使菜单栏项目和项目的项目变得越来越小,我之前已经在这里进行过一段时间的搜索(所以请不要将其标记为重复请)并且我发现的任何post都没有工作。 我尝试了以下代码但没有成功: Font f = new Font(“sans-serif”, Font.PLAIN, 12); UIManager.put(“menuBar.font”, f); 和 menuBar.setFont(new Font(menuBar.getFont().getFontName(), menuBar.getFont().getStyle(), 12)); 这是我的代码,我正在尝试编辑字体: private class foo{ private JMenu mnArchivo; private JMenuBar menuBar; menuBar = new JMenuBar(); frmAdministracinHospital.setJMenuBar(menuBar); JRadioButtonMenuItem rdbtnmntmGrande = new JRadioButtonMenuItem(“Grande”); rdbtnmntmGrande.addActionListener(new MiGrandeActionListener()); rdbtnmntmGrande.setIcon(new ImageIcon(PrincipalWindow.class.getResource(“/presentacion/fontbig.png”))); buttonGroup.add(rdbtnmntmGrande); mnTamanoFuente.add(rdbtnmntmGrande); private class MiGrandeActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { Font f […]

如何用光泽颜色创建JMenuBar?

我创建了一个基于Swing的小应用程序。 为此,我使用JMenuBar类创建了一个菜单栏。 但我想为该菜单栏应用光泽颜色。 特别是,我看看这里看到的效果:第五个例子中的渐变色和第七个中的动画。 我的代码: public class MenuBar extends javax.swing.JFrame { /** * Creates new form MenuBar */ public MenuBar() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the […]

JMenuBar SelectionModel ChangeListener仅触发一次

我试图让我的JMenuBar模拟Firefox和iTunes菜单栏的行为。 行为:菜单栏最初是隐藏的。 但是,当您按Alt ,会出现菜单栏(选择第一个项目),当您没有选择菜单项时,菜单栏会消失。 我的想法是通过其SelectionModel上的ChangeListener监听JMenuBar选择更改。 但是,附加的SSCCE的行为并不理想。 框架加载时, JMenuBar不可见。 按Alt ,会出现菜单栏,并选择第一个菜单(感谢WindowsLookAndFeel )。 但是,每次后续的Alt按下都不会触发ChangeEvents 。 我无法弄清楚为什么…… 有人有光照吗? public class MenuBarTest extends javax.swing.JFrame { public MenuBarTest() { initComponents(); jMenuBar1.setVisible(false); jMenuBar1.getSelectionModel().addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { System.out.println(e.toString()); jMenuBar1.setVisible(jMenuBar1.isSelected()); System.out.println(jMenuBar1.isSelected()); System.out.println(jMenuBar1.getSelectionModel().isSelected()); } }); } private void initComponents() { jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem1 […]

我最大化JInternalFrame时在JInternalFrame上编写JMenubar示例

嗨我需要一个示例程序,当我最大化JInternalFrame时,JFrame的JMenuBar应该设置在JInternalFrame上,当我再次最小化JInternalFrame时,JMenuBar应该离开JinternalFrame并设置为JFrame,如下所示 请在Java Swing中提供一个示例程序

让JButton像JMenu一样行事

我有一个JMenuBar的以下代码(此代码取自一个免费的Java程序调用JGuiD并为个人目的编辑) 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); makeFileMenu(); makeEditMenu(); makeCodeButton(); makeHelpMenu(); } void makeFileMenu() { m_file = new JMenu(“File”); m_file.setMnemonic(‘F’); mi_f_new = new JMenuItem(“New”,new ImageIcon(“icons/new_project.png”)); mi_f_new.setMnemonic(‘N’); mi_f_open = new […]

Swing应用程序菜单名称在Java 1.8中无法正确显示

好的,所以我之前已经完成了Swing应用程序,并且我知道如果你想为应用程序菜单显示一个不同的名称(通常具有“首选项”和“退出”选项的Mac上的那个),你必须使用: System.setProperty(“com.apple.mrj.application.apple.menu.about.name”, “App name”); 它必须在创建JFrame之前执行。 我已经完成了这个,但它继续显示我的Main类的名称作为菜单名称,就好像我根本没有编写那行代码。 我搜索了这个问题,但找不到任何有用的东西,然后我就在这里搜索,但是每个遇到类似问题的人都在运行Java 1.5,1.6或1.7。 所以我想也许它与我目前的Java版本1.8有关。 这个 , 这个 , 这个没用。 这个 , 这个 , 这要么发送给我过时的信息,要么链接不再起作用了。 另外,我正在运行Mac 10.8。 任何建议/答案将不胜感激。 更新: 这是我原来的代码: package bouncing_off_axes; /** * This is the driver class of this program. * * @author Mason * */ public class Main { /** * The driving method. * * @param args […]

Java – 是否可以将JMenuBar添加到JFrame的装饰窗口?

我想知道我是否可以将JMenuBar添加到JFrame或JRootPane的装饰窗口,或者是否包含内容窗格内的边框。 我看到像Firefox或Photoshop这样的应用程序在装饰窗口中有他们的菜单栏。 这可能吗? 我环顾四周谷歌,但我没有找到任何结果这种事情。 我希望Java具备这种能力。

Java JMenuItem ActionListener

我的JMenuBar上的ActionListener需要一些帮助。 没有错误; 但是每次单击JMenuItem时,它都会触发与JMenuItem关联的所有操作。 我的问题是:我在ActionListener代码中做得对吗? 我对ActionListener类不太确定。 我正在尝试将我的ActionListener与Button逻辑分开。 如果有人对我可能做错了什么有任何想法,请指出。 这是我的代码: package MenuBar; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class SimpleMenuBar{ private static final LayoutManager grid = new GridLayout(0, 1); public JMenuBar MenuBar; public JMenu MenuFile, MenuEdit, MenuOption; public JMenuItem ItemNew, ItemOpen, ItemSave, ItemExit, ItemCopy, ItemCut, ItemPaste; ButtonGroup direction; JRadioButtonMenuItem forwardradio, backwardradio; JCheckBoxMenuItem CheckCase; String input = […]

更改其中的JMenuBar和JMenu对象的背景和文本颜色

如何为其中的JMenuBar和JMenu对象设置自定义背景颜色? 我试过.setBackgroundColor它不起作用!

将JMenuBar添加到JPanel?

我有一个JMenuBar和一个JPanel。 我想将JMenuBar添加到JPanel。 我该怎么办?