swingutilities

Why should I use a separate thread to show a GUI in JAVA

谁说胖子不能爱 提交于 2019-12-06 07:18:28
问题 This simple issue confuses me. You can display a JAVA GUI application by setting the frames' setVisible property true . But in almost all the examples I found on internet they use a separate thread to do the same thing. They do something like this, SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new Frame().setvisible(true); //just take the idea of this line } }); I found no difference between the two methods. But there must be some special reason, that's why

SwingUtilites: how to return values from another thread in Java?

人盡茶涼 提交于 2019-12-06 01:01:04
问题 I am trying to make an application in Java. To make Swing work correctly, I did this: public static void main(String[] array){ String outerInput; SwingUtilities.invokeLater(new Runnable(){ @Override public void run() { // I want this string input. String input = JOptionPane.showInputDialog( null,"Stop ?", JOptionPane.QUESTION_MESSAGE); }); // How can I get this input value in String outerInput? } How would I get this input string in my main body? 回答1: How would I get this input string in my

SwingUtilites: how to return values from another thread in Java?

天涯浪子 提交于 2019-12-04 07:36:13
I am trying to make an application in Java. To make Swing work correctly, I did this: public static void main(String[] array){ String outerInput; SwingUtilities.invokeLater(new Runnable(){ @Override public void run() { // I want this string input. String input = JOptionPane.showInputDialog( null,"Stop ?", JOptionPane.QUESTION_MESSAGE); }); // How can I get this input value in String outerInput? } How would I get this input string in my main body? How would I get this input string in my main body? You wouldn't. The idea that your "main" would invoke a Swing dialog box and then do something with

How can I use SwingExplorer to navigate Applet content?

半城伤御伤魂 提交于 2019-12-02 23:49:10
问题 There is SwingExplorer tool from this site http://www.swingexplorer.com/ that used to navigate swing content but how do I apply it to Applet?,especially if I want to integrate it to eclipse-plugin how do I configure the running configuration? I guess that you need to supply the parameter of the applet that you want to run to AppletViwer and let the SwingExplorer navigate the AppletViewer(which in turn run your applet class) but i don't know how to pass such parameter to AppletViwer,Can anyone

Why do I need Swing Utilities and how do I use it?

亡梦爱人 提交于 2019-12-02 00:20:16
问题 This is mainly in regards to my question here, but I don't understand why Swing Utilities is needed and what it is used for. I'm designing a swing gui and I don't wanna miss out on anything that Swing Utilities might offer. Also could someone could explain what the invokeLater method does and how it works. 回答1: As stated in the API, SwingUtilities is a collection of utility methods for Swing. In this case, it is needed to ensure that Swing components are created/modified in the Event Dispatch

What is SwingUtilities.invokeLater [duplicate]

南笙酒味 提交于 2019-11-29 03:43:09
Possible Duplicate: What does SwingUtilities.invokeLater do? SwingUtilities.invokeLater I have seen this little piece of code hundreds of times: public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } Now my question is: what does invokeLater() do? What kind of bad things will happen if I just create and show my GUI inside the main thread? Nothing bad will happen if you're updating it from the EDT while following guidelines . That is... If invokeLater is called from the event dispatching thread -- for

Main purpose of SwingUtilities invokeLater

元气小坏坏 提交于 2019-11-28 13:08:52
I have this code snippet import javax.swing.SwingUtilities; public class Client1 { public static void main( String[] args ) { SwingUtilities.invokeLater( new Runnable() { public void run() { //new MyWindow( "Bayog" ); new MyWindowV2( "Bayog" ); } } ); } } what is the difference if i will not use SwingUtilities? Suppose the code within the run method modifies a UI element. If you try to execute that code from a non-UI thread, it will fail: all UI operations must be performed in the UI thread (aka the event dispatch thread ). SwingUtilities.invokeLater allows you to say "run this bit of code,

Best practice to start a swing application

徘徊边缘 提交于 2019-11-28 12:26:15
What is the best practice way to start a java swing application? Maybe there is another way to do it. I want to know if i have to use the SwingUtilities class to start the application (secound possibility) or not (first possibility). public class MyFrame extends JFrame { public void createAndShowGUI() { this.setSize(300, 300); this.setDefaultCloseOperation(EXIT_ON_CLOSE); // add components and stuff this.setVisible(true); } public static void main(String[] args) { // First possibility MyFrame mf = new MyFrame(); mf.createAndShowGUI(); // Secound possibility SwingUtilities.invokeLater(new

Java Mouse Event Right Click

北慕城南 提交于 2019-11-27 18:14:25
On my three button mouse MouseEvent.BUTTON2 = Middle Click and MouseEvent.BUTTON3 = Right Click. Is this the case on a two button mouse? Thanks To avoid any ambiguity, use the utilities methods from SwingUtilities : SwingUtilities.isLeftMouseButton(MouseEvent anEvent) SwingUtilities.isRightMouseButton(MouseEvent anEvent) SwingUtilities.isMiddleMouseButton(MouseEvent anEvent) Codemwnci Yes, take a look at this thread which talks about the differences between platforms. How to detect right-click event for Mac OS BUTTON3 is the same across all platforms, being equal to the right mouse button.

Java/Swing: Obtain Window/JFrame from inside a JPanel

孤街醉人 提交于 2019-11-27 11:37:52
How can I get the JFrame in which a JPanel is living? My current solution is to ask the panel for it's parent (and so on) until I find a Window: Container parent = this; // this is a JPanel do { parent = parent.getParent(); } while (!(parent instanceof Window) && parent != null); if (parent != null) { // found a parent Window } Is there a more elegant way, a method in the Standard Library may be? You could use SwingUtilities.getWindowAncestor(...) method that will return a Window that you could cast to your top level type. JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this);