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 7 years ago.
Improve this question
I currently have a menu, that whenever I click on one of the options, I want to clear the screen (to clear all my JLabels and text areas). I use the code
getContentPane().removeAll();
getContentPane().repaint();
add(comboBoxOptions);
to clear the screen. After that I try to add a combo box, which adds but it doesn't show up. I can click on the options but it's hidden somehow I guess. How could I fix this?
How could I fix this?
Use a CardLayout, see How to Use CardLayout for more details
Swing's layout management API is lazy, it won't update the layout's automatically, it waits till you tell it to. This is a good thing.
You need to use revalidate to force the container hierarchy to be relaid out and repaint to schedule a repaint of the view, for example
getContentPane().removeAll();
add(comboBoxOptions);
revalidate();
repaint();
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 4 months ago.
Improve this question
I have the following, code which almost does what I want except it doesn't automatically stretch to the right, so the whole label can be seen. I've tried different constrains on it, but it doesn't change, setting the JFrame bigger works, but I would like it to resize depending on the label length, so it doesn't occupy more space on the screen than needed.
The UI Window
Run JFrame.pack() to resize the frame according to it's components.
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 6 years ago.
Improve this question
Very general question, I am just confused on what setBorderPainted does. I'm creating a GUI and I need it. What happens if I don't include it in my GUI, will it effect anything?
Thanks
It is a property of javax.swing.AbstractButton.
When you set this property to true, and if the button has a border, it will paint the border.
As far as I know in certain OS like MAC, when you set the background color of the button, only the border of the button is painted with color. Some people will set this property to false so that the background can be seen colored.
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 7 years ago.
Improve this question
I want to set a background image for my JPannel which contains many JTextField and JButton (I used g.drawImage()), but the the components won't appear unless the mouse passes by.
I can't make a JPanel for every component because I have too many of them.
Can anyone please help or point me into the right direction?
It sounds like either you've overridden paint or failed to call super.paintComponent when painting your image.
Make sure that:
You override paintComponent of your JPanel
You call super.paintComponent before you perform any custom painting
For example
Also take a look at Painting in AWT and Swing and Performing Custom Painting for more details about painting in Swing
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm pretty new to Java and I'm currently attempting to make a simple work scheduling program. I'm trying to implement a way to add employee's and their info into but I'm a little stuck.
What I wanted to do was have a button that opens up a new window that will let me input their name (string), total hours to work per week (int), and their availability (array, check boxes that will translate to an array). Is it possible to customize a JDialog to do this or is there a better way to go about doing this? I tried reading tutorials on JDialogs but none of it explains how to implement multiple inputs.
I currently have it to where I'm opening up a new JFrame but I've read from multiple sources that I shouldn't do that.
Thanks for any help.
I tried reading tutorials on JDialogs but none of it explains how to implement multiple inputs.
This is no different than adding multiple components such as JTextFields, JRadioButtons, JComboBoxes in a JFrame. For both you'd create a main JPanel to hold the GUI, and then give it components and or other JPanels each using its own layout manager. Then create your JDialog or JFrame (using the API to see which constructor to use), add your main JPanel to the top level window (actually to its contentPane) by calling add(myMainPanel), pack the top level window by calling pack(), and display it via setVisible(true).
The key issue for a dialog window is often when to query its contents. If it's a modal dialog, then that's easy -- you query the contents (the state of its fields) after the call to display the dialog, since that code flow will resume once the dialog is no longer visible. For a non-modal dialog, then you'd need to add a WindowListener to notify you when the dialog is no longer visible.
For more specific help, you need to ask a more specific question and show code.
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 8 years ago.
Improve this question
I have a problem with my project. I'm making a tool for numerical methods (a lesson in college). I have done nearly all of the project but I have a problem with my design.
When I resize it before making anything it resizes well but, if I set the size of the matrix after the matrice processes the panel isn't resizing.
The code works well if the rank is <=5, but the bigger matrices cause that problem.
I'm using window builder and the code is messy but I'll be glad if you try to help me.
Thanks for your helps!
Some of things that I noticed in your code.
Don't use null layout at all and avoid setBounds() method
Always hand over it to Layout manager to set the position and size the components.
Use ActionListener for JButton instead of MouseListener if you want to capture click event only.
Note: I can't run your code on my system due to character encoding issue. You have used some character other than English in your code.