jmenuitem

Align icon and JCheckbox in JPopupmenu

时光怂恿深爱的人放手 提交于 2019-12-31 01:11:15
问题 I have a Problem with some icons and check-boxes in a JPopupMenu . The Check-boxes and Icons are not aligned The Items are created like: JMenuItem deleteAttributeMenuItem = new JMenuItem(locale.getString("TREE_AttrDelete"), iconDelete); JMenuItem primaryKeyAttributeMenuItem = new JCheckBoxMenuItem(locale.getString("TREE_AttrChkBoxPK")); Please take a look at the picture: Any tips? 回答1: Have a look at this, in order to achieve what you wanted, I did this, JCheckBoxMenuItem cbmi = new

Java JMenuItem ActionListener

放肆的年华 提交于 2019-12-30 08:56:49
问题 I need some help with my ActionListener on my JMenuBar. There's no error; however every time I click on a JMenuItem, it triggers all the action associated with the JMenuItem. My question is: am I doing it right in my ActionListener code? I'm not too sure about my ActionListener class. I'm trying to separate my ActionListener from my Button logic. If anyone has any ideas on what I may be doing wrong, please point it out. Here is my code: package MenuBar; import java.awt.*; import javax.swing.*

Command Pattern Usefulness when using JComponents

我的未来我决定 提交于 2019-12-29 07:06:13
问题 So, I'm developing a program using the Swing library and I obviously have buttons and menu items. Some of these are supposed to do the same stuff, and I thought using the Command Pattern should be the way to do it, e.g. I have a "save" button and a "save" menu item and they have to implement the same saving algorithm. Command Pattern seems to be ok but I can't get who's the receiver in all that. Isn't a comand supposed to work on an object which implements some sort of "receiver interface",

Java Swing OSX Window Menu Icon Alignment

落花浮王杯 提交于 2019-12-29 02:16:50
问题 Java Swing seems to place the 'Menu Text' after the icon (if present) on MenuItems. See example below. It does NOT look very nice. Is there a way around this? On OSX the icon fits in the left margin and the text aligns with all other MenuItems. 回答1: Do you mean something like this : import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JTextPaneExample { private Icon info = UIManager.getIcon("OptionPane.informationIcon"); private Icon error = UIManager.getIcon(

Is it possible to make some items in the menu to fade in with 500 ms onset delay in Java?

泪湿孤枕 提交于 2019-12-25 07:18:28
问题 I have a JMenu of 16 JMenuItems, of which I want 3 items to be displayed upfront and the rest 13 items to fade in with a 500 ms delay. Is there a way to do this animation in Java? 回答1: This is not as easy as it sounds. Basically I originally thought "I'll attach a popup listener to the popup menu that the menu items are added to"...but apparently this doesn't work so well. The menu popup is built dynamically on demand. Makes sense, but it's still a pain. So instead, I've found that if I wait

How do I change the direction of JMenus in a JMenuBar

℡╲_俬逩灬. 提交于 2019-12-24 14:57:36
问题 When I create a menu in java GUI by using JMenuBar it puts all JMenu s from Left-to-right direction like this: I want to change it to Right-to-left like this: I want do this in an English OS, so suggestions of an Arabic or Right-to-Left solution aren't what I'm looking for. 回答1: You can use Component.applyComponentOrientation to change the orientation of the JMenuBar : import javax.swing.*; import java.awt.*; public class R_L_MenuBar_Demo { public static void main(String[] args){

Creating JMenuitem's in a for loop

我是研究僧i 提交于 2019-12-24 03:35:23
问题 Greeting, I'm trying to do this: public float a=0; for(a=1 ; a<100;a++){ String fuent="font"+String.valueOf((int)a); JMenuItem fuent=new JMenuItem(String.valueOf(a)); fuent.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){texto.setFont(texto.getFont().deriveFont(a)); current=a;}}); tamano.add(fuent); } But it throws these errors: cambiar.java:71: error: variable fuent is already defined in constructor cambiar() JMenuItem fuent=new JMenuItem(String.valueOf(a))

How can I add to or change a label on a JMenuItem?

╄→尐↘猪︶ㄣ 提交于 2019-12-23 12:44:14
问题 I need to add a label on the right hand side of a JMenuItem , like the labels shown below: I have an application that uses Ctrl + + and Ctrl + - to zoom into an image. However, the + key by default (without Shift ) is the = key. When I try adding accelerators for these menu items, the Ctrl + - shortcut label displays as "Ctrl+Minus" (I would prefer "Ctrl -") and the Ctrl + + shortcut label displays as "Ctrl+Equals" (even worse - in the interest of user experience, I would prefer "Ctrl +"):

How to Reset the check state and uncheck state of Menuitems for Multiple documents using swing

假如想象 提交于 2019-12-23 04:27:03
问题 I want to Reset the state of checkboxMenuItems.For example I create More than one Document then add some text to recently opened document and select LineNumbers then I go to previos opened Document at that time the linenumbers checkbox is reset to original state that is unselect state whether I select it in "check state" in another Dcoument.please help me.Thank you. Here is code: import javax.swing.JInternalFrame; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax

Disable menu items programmatically

試著忘記壹切 提交于 2019-12-14 04:19:36
问题 I am working on a Desktop app with the Netbeans RCP. I have a number of menu items that are beeing added to the menu through annotations in the TopComponents. I would like to be able to disable several of these menu items, depending on the access rights of the logged user. 回答1: One way to do this in the NetBeans Platform is to register a Presenter.Menu in the menu: @ActionID(id = "com.company.MyPresenter", category = "Edit") @ActionRegistration(displayName = "com.company.Bundle#CTL