Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a main JFrame with a button that generates another JFrame. However, when I close the 2nd JFrame the main JFrame is also closed which is not what I want. What am I doing wrong?
I assume you're setting the default closing action as:
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
The JFrame.EXIT_ON_CLOSE constant terminates the whole program when you click the x button. You probably want to use DISPOSE_ON_CLOSE or HIDE_ON_CLOSE instead. I recommend to have a look at the JavaDoc of JFrame.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
When i start the Jframe "VentanaPrincipal" this one looks like this:
but when I open the Jframe from another Jframe, it changes the format of the components:
My code is:
VentanaPrincipal vp = new VentanaPrincipal();
vp.setVisible(true);
Can you please help me?
The Look and Feel (LAF) is changing.
Swing components use the LAF at the time the component is created.
It would seem that one frame uses a different LAF so the second frame inherits that LAF when it is created.
Fix your code to use the same LAF.
Read the section from the Swing tutorial on Modifying the Look and Feel for more information.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
Cheers, lads.
I am currently standing in front of a minor problem, but it really drives me insane, that I'm not able to fix it.
My very first mistake was to use my main-JFrame as main-class, as well.
You will see why this is (as far as I am able to judge) a problem later...
Now I am opening a new JFrame from my main-class-main-JFrame and I want to disable it as long as the new JFrame is opened.
I've already read much about using JDialog to do this, but I did not yet managed to find a solution without having to redesign my whole sub-JFrame.
Is there an easy way to just disable the mainJFrame as long as the subJFrame is opened?
Something like:
JFrame subframe = new GUI_subJFrame(<params>);
this.disable();
subframe.onClose(this.enable());
I know this is awful and not existent source code, but I wanted to make my thought clear, accurately.
I just changed the "subJFrame" from JFrame to JDialog and added the following line to the constructor:
this.setModalityType(DEFAULT_MODALITY_TYPE);
It works fine and is not as complicated as it seemed at first glance.
Thanks to everyone for their help.
Use frame.dispose(); to close the frame
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I was wondering is it possible to add a window to another window? Like can you add that window, like an internal frame to another window. The reason why I am asking this is because I want the image window (which is produced by ImageJ) to be displayed in a desktop frame or window. Also how would you go about doing this. Thanks in advance.
You can call the getContentPane() method of a JFrame, or more generally the getComponents() method of Container (e.g., in the case of java.awt.Frame or java.awt.Dialog windows) and then set it as the content pane of a JInternalFrame.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
Basically I have two panels and one label. I want this label to show in the exact same position on both panels(I'm using the card layout). But when I use the same component it doesn't show up on either panel, but it does if it's only being used on one panel. Does anyone know why?
Thanks.
No you can't do that. A Swing component can only have 1 parent.
But you might be able to create 2 JLabel objects, and give them the same Model, so they always show/contains the same data.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I would like to make a simple component that does nothing other than draw an arbitrary image, and then directly beneath it place a JLabel for displaying arbitrary text.
How can I achieve this? I'm brand new to Swing and I'm trying to learn as I go, but I don't currently understand how I would go about doing this. I know it's a basic question, and I appreciate any help I can get.
JLabel is your friend:
JLabel label = new JLabel("Your text here");
label.setHorizontalTextPosition(SwingConstants.CENTER);
label.setVerticalTextPosition(SwingConstants.BOTTOM);
label.setIcon(new ImageIcon(this.getClass().getResource("/path/to/image/image.jpg")));