jmenuitem

Double icons with JMenuItem setHorizontalTextPosition on Win

爷,独闯天下 提交于 2021-02-07 18:28:38
问题 Two icons are rendered when using JMenuItem setHorizontalTextPosition(SwingConstants.LEFT) with Windows Look and Feel. It works fine with the default Java Look and Feel. I just filed a Java bug report, posting here for anyone else having the same problem. Does anyone have another workaround to suggest? Thanks. import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax

Add image to JCheckBoxMenuItem

眉间皱痕 提交于 2021-01-28 06:09:50
问题 I have been given an assignment in which i need to a use JCheckBoxMenuItem and add an image to it on the right side I've used the setIcon() method. Created a custom panel and added image to it and then adding the panel to checkbox. Tried to add panel like below. JCheckBoxMenuItem item = new JCheckBoxMenuItem(); item.setText("Option1"); JPanel panel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); JLabel label = new JLabel(new ImageIcon( "C:\\Users\\abcd\\Desktop\\facebook.jpg")); panel.add

Java menu item enabling within event listener

你离开我真会死。 提交于 2021-01-27 11:27:51
问题 Hello im trying to enable my JMenuItem from within an event listener but it seems to be out of scope. im new to java so how would i properly go about this. the said event listener will change to a new view and enable the disabled menu items. //Create and add MenuItems JMenuItem fileItem0 = new JMenuItem("Load"); collMenu.add(fileItem0); JMenuItem fileItem1 = new JMenuItem("Add"); fileItem1.setEnabled(false); collMenu.add(fileItem1); JMenuItem fileItem2 = new JMenuItem("Delete"); fileItem2

Java menu item enabling within event listener

我只是一个虾纸丫 提交于 2021-01-27 11:24:52
问题 Hello im trying to enable my JMenuItem from within an event listener but it seems to be out of scope. im new to java so how would i properly go about this. the said event listener will change to a new view and enable the disabled menu items. //Create and add MenuItems JMenuItem fileItem0 = new JMenuItem("Load"); collMenu.add(fileItem0); JMenuItem fileItem1 = new JMenuItem("Add"); fileItem1.setEnabled(false); collMenu.add(fileItem1); JMenuItem fileItem2 = new JMenuItem("Delete"); fileItem2

How to import an image in menu bar

眉间皱痕 提交于 2020-01-16 03:55:10
问题 I've created a simple menu bar and I don't know how to import an image in the free space. My code is below: import java.awt.event.*; import java.awt.*; import javax.swing.*; import java.io.IOException; public class MyMenu extends JFrame { JMenuBar menubar; JMenu file, edit, contact, quit; JMenuItem exit, open, search, delete, registration, informations; public MyMenu() { setLayout(new FlowLayout()); //___________________________ FILE __________________________________ menubar = new JMenuBar()

Custom JMenuItems in Java

不羁岁月 提交于 2020-01-10 10:34:01
问题 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 ] | +----------------------------------------+ 回答1: 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");

Custom JMenuItems in Java

ⅰ亾dé卋堺 提交于 2020-01-10 10:33:49
问题 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 ] | +----------------------------------------+ 回答1: 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");

JPopupMenu not showing on the screen?

不想你离开。 提交于 2020-01-06 14:03:00
问题 So for my school project I am creating a Class Diagram maker. I am 95% done with it and all I need is to make the Jpopup menu appear. In the core I have 3 files. The ApplicationModel which extends the JFrame, ClassDiagram which extends the JPanel and ClassModel which makes the Rectangles (in the picture) appear. The core of the rendering is on Rectangle objects and the text inside the middle and bottom rectangles are surrounded by another invisible rectangle, which is right-clickable. This is

How to prevent JMenuItem from closing Menu upon clicking the JMenuItem

一曲冷凌霜 提交于 2020-01-02 07:45:10
问题 How do I prevent a JMenuItem from closing the menu when the JMenuItem is clicked? The JMenuItem is enabled. So this is the scenario, I have 3 JMenuItems : JMenuItem: A, B, C ; C displays an integer X . A and B are used to increment or decrement X by a value of 1. If A or B is clicked, the default nature is that the menu will close upon click. I want to be able to repeatedly click A or B and have the menu remain up, and perform the associated 'action' upon each click. Thanks! 回答1: First, using

Align icon and JCheckbox in JPopupmenu

…衆ロ難τιáo~ 提交于 2019-12-31 01:11:22
问题 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