jdialog

Hide JDialog window when the window lost focus

梦想与她 提交于 2019-12-24 07:29:03
问题 Hi I have only one JDialog box in my Java application.I want to make it invisible if it lost the focus. I've tried different method, But didn't able to trigger any of the window focus events. Here is my code: public void windowGainedFocus(WindowEvent e) { System.out.println("gained focus"); } public void windowLostFocus(WindowEvent e) { System.out.println("lost focus"); } 回答1: Responding to Focus events can be really tricky. My experience has been that pretty much any time someone has

Pause execution until the child dialog is closed

时光总嘲笑我的痴心妄想 提交于 2019-12-24 05:54:28
问题 I am trying to open a JDialog from JFrame . I want to pause the execution until the child dialog is being closed, but the main frame is being executed continuously without any pause. I am using the following code. What is alternate solution? Class NewFrame extends JFrame NewFrame() try { NewDialog frm = new NewDialog(); frm.show(); JOptionPane.showMessageDialog(null,"yes"); } catch(Exception ex) { ex.printStackTrace(); } } } In the above program I want a message should be displayed when the

JDialog with transparent background which blurs things underneath

丶灬走出姿态 提交于 2019-12-24 05:18:07
问题 I'm trying to make a transparent JDialog, which blures what´s underneath it (for better readability). Already found this link, but there the contents of the dialog are blurred. Also I found this, but there everything (things underneath and contents of the Dialog) is blured and it's flickering. Here's a screenshot for better understanding: The top is what I already have and the bottom what I want to achieve. 回答1: After some testing it appears to be pretty tricky to get something like what you

JDialog misbehaviour

爷,独闯天下 提交于 2019-12-24 03:25:22
问题 JDialog dialog = new JDialog(parent JFrame, "blabla"); dialog.setLayout(new BorderLayout()); JLabel label = new JLabel("more blabla"); dialog.getContentPane().add(label, BorderLayout.CENTER); dialog.setSize(new Dimension(280, 80)); dialog.setLocationRelativeTo(parent JFrame); dialog.setVisible(true); //part of code that takes time to execute //actually, I'm sending an email here, but it doesn't really matter what I do, //as you will read below dialog.dispose(); I have the code above and it's

How to make the JDialog invisible when the JProgressBar reaches 100%?

对着背影说爱祢 提交于 2019-12-24 03:06:49
问题 Relevant piece of code: JProgressBar progress; JButton button; JDialog dialog; //Fields of my GUI class progress=new JProgressBar(JProgressBar.HORIZONTAL,0,100); button=new JButton("Done"); dialog=new JDialog(); //Done from methods progress.setValue(0); progress.setStringPainted(true); progress.setBorderPainted(true); //Also done from methods button.addActionListener(this); //Also done from methods dialog.setLayout(new FlowLayout(FlowLayout.CENTER)); dialog.setTitle("Please wait..."); dialog

Add a JLabel in the JTabbedPane header

纵饮孤独 提交于 2019-12-24 00:42:11
问题 I have this JDialog with a JTabbedPane: I just want to add a JLabel in the right-top area of the JTabbedPane so i can fire some events (e.g close the JDialog). And i don't want to make it a JFrame. PS: I know that is may be duplicated, but none of the responses give me a solution. 回答1: Well, actually that positioning inside JTabbedPane is not supported in Swing. But you can always make some street magic with layouts and layers: public static void main ( String[] args ) { try { UIManager

JFrame.getLocationOnScreen() for minimized window

倖福魔咒の 提交于 2019-12-23 20:19:03
问题 I call getLocationOnScreen() from JFrame in my Swing application. If JFrame is minimized -32000, -32000 is returned. It is expected: Location Coordinates On Computer Showing X=-32000, Y=-32000 But I need to know the location of the window before it was minimized or would be the location if it is maximized again without actual maximizing it. Because I need to position JDialog relatively to the JFrame even though it is minimized. Possible solution: Add WindowListener to JFrame and on

JDialog with WindowListener - windowClosing not fired

最后都变了- 提交于 2019-12-23 12:46:37
问题 I have a class that extends JDialog that have a window listener: class MyClass extends JDialog { public MyClass() { setDefaultCloseOperation( JDialog.DO_NOTHING_ON_CLOSE ); addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.out.println("closing..."); //do something... } }); } } When i click in the X button, nothing happens. And I don't see the print of "closing..." What I am missing? 回答1: Works for me. See also this related example. import

JInternalFrame As Modal

混江龙づ霸主 提交于 2019-12-23 03:22:17
问题 I Have the following code: import java.awt.AWTEvent; import java.awt.ActiveEvent; import java.awt.Component; import java.awt.EventQueue; import java.awt.MenuComponent; import java.awt.event.MouseEvent; import javax.swing.JInternalFrame; import javax.swing.SwingUtilities; public class modalInternalFrame extends JInternalFrame { // indica si aquest es modal o no. boolean modal = false; @Override public void show() { super.show(); if (this.modal) { startModal(); } } @Override public void

Dynamically change the width of JDialog

让人想犯罪 __ 提交于 2019-12-22 18:42:33
问题 I have created a JDialog which contains a JLabel. Because the length of text, which changes based on users' input, can contain a large number of characters, there is the need to dynamically change the length of the JDialog based on the size of length of the JDialog. I have tried the pack() method but it's not the case for it. Can anyone give me some tips? Thanks in advance! 回答1: getPreferredSize for JLabel - basically you have to get textLength from JLabel in pixels, there are 3 correct ways,