jframe

Terminate running threads on JFrame close

匆匆过客 提交于 2019-12-20 23:22:18
问题 How do I invoke extra operations when the user closes a JFrame window? I have to stop existing threads. As I understand it, setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); causes the frame to be closed and its thread to be stopped. Should threads be closed after JFrame.EXIT_ON_CLOSE ? Client: static boolean TERMINATE = false; public static void main(String[] args) { // some threads created while(true) { if(TERMINATE){ // do before frame closed break; } } } private static JPanel startGUI(){

Set location of JDialog relative to JFrame

≡放荡痞女 提交于 2019-12-20 10:57:20
问题 Is there a way to set a dialog location relative to a JFrame ? I would like to center the dialog to the frame that houses my GUI, instead the dialog often appears in the center of the screen rather than within the GUI. 回答1: Is there a way to set a location relative to another JFrame You can: pass JFrame as argument for JDialog.setLocationRelativeTo(Component c) set to desired Point from JFrame to JDialog.setLocation(Point p) EDIT all Swing code must be done on EventDispatchThread, meaning

set JFrame Orientation from right to left!

99封情书 提交于 2019-12-20 10:32:51
问题 To align my JFrame from righ-to-left, I use: setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); but this works only if I use the following style (decoration) of the JFrame: public class RightToLeft { public static void main(String []args){ javax.swing.SwingUtilities.invokeLater(new Runnable(){ public void run() { try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } JFrame.setDefaultLookAndFeelDecorated(true)

set JFrame Orientation from right to left!

99封情书 提交于 2019-12-20 10:31:14
问题 To align my JFrame from righ-to-left, I use: setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); but this works only if I use the following style (decoration) of the JFrame: public class RightToLeft { public static void main(String []args){ javax.swing.SwingUtilities.invokeLater(new Runnable(){ public void run() { try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } JFrame.setDefaultLookAndFeelDecorated(true)

Swing: taking variables from two private jTextField?ActionPerformed classes

让人想犯罪 __ 提交于 2019-12-20 07:48:20
问题 I'm in NetBeans 8.2 and I've constructed a nice jFrame GUI for a Binary-to-Decimal converter, I think I have the code in my two text fields correct but I can't figure out how to access the variables for my Button to perform operations on. I have 3 method operations called parseBinary, isBinary, and illegal that I want to use to perform operations on my two text fields. In NetBeans when you code a button the method is locked to private so that's my issue. I will post all my of code and

JFrame not displaying all images in fullscreen

纵饮孤独 提交于 2019-12-20 07:15:03
问题 So, I am working on a project which requires switching between images. The images need to be in fullscreen mode. There seem to be 2 problems that I am facing. First is with the image switching. When I switch between images, some images appear ok when I switch. Others dont seem to show up on the screen at all. I just seem to be getting an empty frame. Second is that the right key seems to work everytime but just for my sanity, I have put system prints. The system outs dont seem to show up on

Calling repaint from another class JFrame

。_饼干妹妹 提交于 2019-12-20 07:10:31
问题 I'm trying to call repaint from another class. But it does not work. I have to draw on a frame. public class Tester extends JFrame{ public static dtest d ; public static void main(String[] args) { Tester t = new Tester(); d = new dtest(); test tnew = new test(); } public static class dtest extends JFrame implements MouseMotionListener{ public static int x,y; dtest() { super("title"); setSize(500,500); setVisible(true); addMouseMotionListener(this); } @Override public void mouseDragged

JFrame not opening when a button is clicked

前提是你 提交于 2019-12-20 07:10:16
问题 I have two JFrame . public class Main extends JFrame public class ColourOption extends JPanel implements ActionListener which is then set up in a JFrame. I wanted to open the second JFrame when i click on button of first JFrame .setVisible() is not working. I also tried revalidate() , as well as invalidate() , validate() in the second JFrame. What could be the reason for it to not work? 回答1: You will have to instantiate the 2nd class which has the 2nd Frame(to be shown)..and then if you call

JFrame does not add component when JButton is pressed

断了今生、忘了曾经 提交于 2019-12-20 06:39:50
问题 My code is basically about having a frame and it has a button. You press the button you can draw rectangles, getting coordinates from the mouse press and the mouse release. Now, if you remove the button the code works perfectly, here is the code. //testing file package ActionTest; import java.awt.*; import javax.swing.*; public class MouseTest { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { JFrame frame = new MouseFrame(); frame.setTitle(

java custom shaped frame using image [duplicate]

旧时模样 提交于 2019-12-20 06:29:31
问题 This question already has answers here : Image/Graphic into a Shape (3 answers) Closed 5 years ago . i like to create a java jframe look like this image.i have already crated jframes with different shapes like triangles ,circles ,polygons and some crazy shapes .but the problem it's too hard[99% impossible ] to create shape like this image.so how can i make a jframe like this.i used this code for create shaped window.. setUndecorated(true); Polygon polygon = new Polygon(); polygon.addPoint(0,