swing

How to prevent the TrayIcon popup to occupy the whole dispatcher thread

扶醉桌前 提交于 2021-02-19 08:12:30
问题 I have a java application that uses a JFrame as well as a TrayIcon and I added a PopupMenu to the TrayIcon . When I click on the TrayIcon the popup menu shows up, but the main frame freezes as long as the PopupMenu is visible. My first thought was that the event dispatch thread is occupied by someone. So I wrote a small example application that uses a swing worker and a progress bar. public class TrayIconTest { public static void main(String[] args) throws AWTException { JFrame frame = new

Starting threads from inside EDT event handler code in Swing apps

喜夏-厌秋 提交于 2021-02-19 08:11:26
问题 My understanding of the Swing Event Dispatcher Thread (EDT) is that its a dedicated thread where event handling code is executed. So, if my understanding is correct, then in the example below: private class ButtonClickListener implements ActionListener{ public void actionPerformed(ActionEvent e) { // START EDT String command = e.getActionCommand(); if( command.equals( "OK" )) { statusLabel.setText("Ok Button clicked."); } else if( command.equals( "Submit" ) ) { statusLabel.setText("Submit

Detect if any mouse button is being pressed, and if so, which one?

点点圈 提交于 2021-02-19 07:40:49
问题 Basically, I want to query if any mouse button is being pressed and if so, which one. The problem is that I don't use a (constantly focused) UI environment. It is meant to be able to run in the background while the OS is focused on another window. I just have a Swing GUI set up for easy controlling. How could I do this? (By the way, I am trying to query it inside of a loop, so setting up an event listener wouldn't be efficient.) 回答1: As mentioned by others you would need to use JNA in order

Detect if any mouse button is being pressed, and if so, which one?

南楼画角 提交于 2021-02-19 07:39:31
问题 Basically, I want to query if any mouse button is being pressed and if so, which one. The problem is that I don't use a (constantly focused) UI environment. It is meant to be able to run in the background while the OS is focused on another window. I just have a Swing GUI set up for easy controlling. How could I do this? (By the way, I am trying to query it inside of a loop, so setting up an event listener wouldn't be efficient.) 回答1: As mentioned by others you would need to use JNA in order

How can I rotate an onscreen component in Java?

本秂侑毒 提交于 2021-02-19 06:48:25
问题 import javax.swing.*; import java.awt.*; public class JFrameAnimationTest extends JFrame { public static void main(String[] args) throws Exception{ AnimationPanel animation = new AnimationPanel(); JFrameAnimationTest frame = new JFrameAnimationTest(); frame.setSize(600, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(animation); frame.setVisible(true); for(int i = 0; i < 100; i++) { animation.incX(1); //animation.incY(1); animation

how to load Tree inside JComboBox?

早过忘川 提交于 2021-02-19 05:23:25
问题 How can I show a tree inside a JComboBox popup? Here is example tree: Theoretical computer science Mathematical logic Automata theory Algorithms and data structures Analysis of algorithms Algorithms 回答1: There is no default way to put a tree in a combo box. There are a couple of options: If you can give allowing expansion of nodes, you can achieve a similar effect by adding space before some of the options in a standard JComobBox. Or even space and a dash in front of leaf options. If you need

how to load Tree inside JComboBox?

戏子无情 提交于 2021-02-19 05:21:07
问题 How can I show a tree inside a JComboBox popup? Here is example tree: Theoretical computer science Mathematical logic Automata theory Algorithms and data structures Analysis of algorithms Algorithms 回答1: There is no default way to put a tree in a combo box. There are a couple of options: If you can give allowing expansion of nodes, you can achieve a similar effect by adding space before some of the options in a standard JComobBox. Or even space and a dash in front of leaf options. If you need

How do I show only the HSV box of a JColorChooser?

佐手、 提交于 2021-02-19 03:35:10
问题 In this image you can see a default Java Swing color chooser, JColorChooser : What I want is just the color square and vertical slider as outlined in red: I was able to remove all the tabs (Swatches, HSL, etc) and the preview, but I was unable to remove all the sliders. How can I do this? 回答1: OK, just for grins, I decided to create your desired JPanel from scratch, wiring it up in a kind of View-Controller set up, since the model here is trivial -- a Color field within the controller. To use

How to save current state of graphics on JPanel [duplicate]

房东的猫 提交于 2021-02-19 03:28:33
问题 This question already has answers here : How to serialize Java 2D Shape objects as XML? (2 answers) Closed 6 years ago . I have a program that lets the user add rectangles and circles to JPanel using Graphics. What I want to be able to do is save the current state of the current JPanel (i.e. all of the shapes and their locations) into a file and be able to load that file back and restore that state. I have a Shapes class that extends JPanel and does all of the drawing and keeps track of the

Undo button for drawings in a JFrame

旧时模样 提交于 2021-02-18 19:10:06
问题 I am drawing some objects on a JFrame such as circles, rectangles and arcs between them. I was wondering how I can implement an Undo button bearing in mind that the ones I found are targeted at text fields and writing in them. I don't have code to show and I wish to receive advice on how to implement it. Is it possible to 'register' the last event that occurred and then delete it? I have a very simple code about deleting the circles for instance. It works only for them and I know that it is