jmenu

JCheckBoxMenuItem only one selected

纵饮孤独 提交于 2019-12-11 06:40:54
问题 So I want to have a JMenu Level with three JCheckBoxMenuItem like Easy, normal and expert. Of course, only one can be checked and if one is checked, it can't be unchecked (enabled(false)) because it's the only one. I want when one JCheck is checked, all others are unchecked. So it seems easy, but the only solution I found is to do it with a lot of "if" conditions. Is there a way to do it with a better algorithm ? 回答1: It sounds like you'd be better off using a JRadioButton since check boxes

How do I build a JMenu dynamically?

别说谁变了你拦得住时间么 提交于 2019-12-11 06:25:27
问题 I am trying to build a JMenu dynamically right when clicking in it (I'm only getting an empty menu), below is my code. final JMenu JMWindows = new JMenu("Opened Windows"); JMWindows.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for(JInternalFrame ji : desktop.getAllFrames()) { JMWindows.add(ji.getTitle()); } } }); I've realized that the actionperformed is never called, the JMenu is inside a JMenuBar . What could be the problem ? 回答1: You add

Why does the compiler not run the program even though there are not any errors?

跟風遠走 提交于 2019-12-11 06:24:25
问题 I have a program that is not showing any errors in Eclipse, but whenever I click the run button, nothing happens. I get the code lines in the compiler console that I have attached below. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Transaction extends JFrame { private static final long serialVersionUID = 1L; JFrame frame = new JFrame("Bank Account - S Standridge"); JMenuBar MenuBar; JMenu File = new JMenu("File"); JMenu Edit = new JMenu("Edit"); JMenu About =

Why does my program compile but it not run?

北战南征 提交于 2019-12-11 05:34:08
问题 This is a follow up question due to changes being made to the OP code. Another user suggested I link the other question to this one. The OP is : Why does the compiler not run the program even though there are not any errors? I have a code that compiles but it does not run. I am trying to get the GUI to run so that I can then add the code to perform the functions I need it to. the code follows as: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Transaction

Why does my program not change the font or size of the font when clicked in the JMenu?

与世无争的帅哥 提交于 2019-12-11 04:57:37
问题 When I try to run the program, it runs fine. The problem is that it does not change anything when the button is clicked. I think the problem is that it is not properly changing the Fonts. It does nothing even when I try to change the sizes but I do not know why that is. Thank you for helping! Here is the code to my program: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JMenuExample5 extends JFrame implements ActionListener{ Container con; JMenuBar menuBar;

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) {

Changing a JMenuBar's font

情到浓时终转凉″ 提交于 2019-12-11 00:43:15
问题 I have problems with setting the font of a JMenuBar . I personally don't like the bold font Java frames use by default, so I tried to change it by using something like this: public class MyFrame extends javax.swing.JFrame { public MyFrame() { JMenuBar menuBar = new JMenuBar(); menuBar.setFont(new Font("sans-serif", Font.PLAIN, 12)); setJMenuBar(menuBar); setSize(600, 400); // add some menus to the menu bar menuBar.add(new JMenu("Foo")); menuBar.add(new JMenu("Bar")); menuBar.add(new JMenu(

scope of the mouse adapter

白昼怎懂夜的黑 提交于 2019-12-10 19:28:01
问题 I am wonder what the scope of the MouseAdapter is in this case. class foo extends JPanel() { private JMenu edit = new JMenu(); public foo() { this.edit.getItem(0).addMouseListener(new MouseAdapter(){ @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 1) { edit.getItem(0).setEnabled(true); } } }); } } I thought the MouseAdapter has access to the variable edit because the newly declared MouseAdapter is an inner class of the class foo . However, it can't find the

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

Setting alignment of title text in a JMenu component

拥有回忆 提交于 2019-12-10 16:27:30
问题 Simply put, JMenu.setHorizontalAligment(SwingConstants.CENTER) does nothing and the text is still left-aligned (using the Windows LAF). Is there any method of aligning the text in a menu header (not the JMenuItem - the JMenus themselves)? I'm using JDK1.7. What my JMenuBar with its JMenus looks like currently: 回答1: I've used CSS to position and style the text in the menus. style="text-align:center;" is the CSS used to position the text in the center in the example image at the bottom. In my