Resize JPanel After Process [closed] - java

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.

Related

JFrame doesn't resize when JLabel gets longer [closed]

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.

how do i set the size of my window gridbaglayout [closed]

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
I'm using gridbaglayout and I want my window to be 700 x 500 always. I also was my JButtons to be the exact same size but if the word inside them is longer they get longer and I can't have this. How can I do this? Please help me with good code I been trying for hours.
I tried to do frame.setSize and panel.setSize but neither work and I need this fast! Please help!
The basic answer is, you don't. That's not the point of any layout manager.
A layout manager simple makes decisions about how best to layout it's children based on the sizing hints that they provide.
Remember, while it might look great on your screen, the next computer you run it on may make it look like crap.
If you "must" define the size of anything, then you need to override the getPreferredSize method of your component and return an appropriate size hint.
Having said that, I wouldn't do this for components like JButton (or actually anything other than JPanel and JComponent), the way they calculate their sizes are complicated and best left alone.
You can modify the size of components through the use of Borders and, in the case of GridBagLayout, Insets and modifying the GridBagConstraints properties.
Have a closer look at How to Use GridBagLayout for some more ideas

Java Swing: How to specify location and size of components? [closed]

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 am still learning java in college but I just would like to know the way or ways to put the JComponent's in specific location and specify their size.
I have seen the methods setLocation() and that sort of methods but I just really wanna know how to put a Component without using those layout managers(flow, grid, border?).
Here is the code I would like to apply that knowledge to: they are two overloaded methods that display the same window.
public void addWelcome()
{
setWindow();
MaxDimension = new Dimension(WelcomeLabelDimensionWidth,WelcomeLabelDimensionHeight);
getWindow().setMaximumSize(MaxDimension);
MinDimension = new Dimension(WelcomeLabelDimensionWidth,WelcomeLabelDimensionHeight);
getWindow().setMinimumSize(MinDimension);
getWindow().setTitle("Bills");
getWindow().setSize(WindowWidth,WindowHeight);
getWindow().setDefaultCloseOperation(EXIT_ON_CLOSE);
getWindow().setLayout(new GridLayout(5,1,2,0));
getWindow().add(getWelcomeLabel());
getWindow().add(getGreetLabel());
getWindow().add(getDescriptionLabel());
getWindow().add(getInstructionLabel());
getWindow().add(getStartButton());
getWindow().pack();
getWindow().setVisible(true);
}
public void addWelcome(final int Width, final int Height)
{
setWindow();
MaxDimension = new Dimension(Width,Height);
getWindow().setMaximumSize(MaxDimension);
MinDimension = new Dimension(Width,Height);
getWindow().setMinimumSize(MinDimension);
getWindow().setTitle("Bills");
getWindow().setSize(WindowWidth,WindowHeight);
getWindow().setDefaultCloseOperation(EXIT_ON_CLOSE);
getWindow().setLayout(new GridLayout(5,1));
getWindow().add(getWelcomeLabel());
getWindow().add(getGreetLabel());
getWindow().add(getDescriptionLabel());
getWindow().add(getInstructionLabel());
getWindow().add(getStartButton());
getWindow().setVisible(true);
}
Apologize if code/question are not clear enough.
Thanks in advance.
You can use an Absolute Layout, which makes you responsible for positioning everything. Do note that this also makes it nigh impossible to create a layout that will be usable with different screen and window sizes (so yeah, learn to use proper layouts).
Yes a layout manager is the best solution
An IDE like eclipse or netbeans can help you effortlessly visually position your components with different layouts.
It autogenerates code which you can easily observe and learn.
If you want to code it yourself you have all resources in this link
http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html

ON/OFF flip button in Swing [closed]

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 wish to create a button exactly same as this (from iOS5).
You will have two images, for ON and for OFF.
Whenever you click the button, you will switch images with button.setImage(..).
Swing constraints:
Button will still be rectangular, even though the image is oval
Animation possible, but quite hard AFAIK. From the way you asked your question, I think it will take you a while to study swing more
In swing, there is JToggleButton which can have two status. However, if you want the button of the same shape and the same visual effect, you should implement it.

Moving a JLabel in a circular path [closed]

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 am.working. on a Netbeans Java project in JFrame form (a GUI application) where I want to move a JLabel into circular path. Can any tell or help to how to do that?
It sounds like you haven't done anything yet, and when that happens and you need to get started, then you should try to break the main problem into little steps, and then try to solve each little step one at a time, including looking at references for each of these steps such as using a Timer, doing animation, positioning components, etc...
So general recommendations:
Look up using a Swing Timer (or just click on link)
Use the Timer to drive your animation.
You can move a JLabel if the layout is null, but this is generally to be avoided.
Consider instead using a custom layout if you absolutely need to move a JComponent (the JLabel) along a prescribed path.
Or if you just want to move an image, then draw the image inside of a JPanel's paintComponent(...) method, setting its position with two int fields that are changed by the Timer. This JPanel of course will need to be displayed in your GUI. There are lots of examples on how to do this on this site, some written by me (for example), that simple searching can help you find.
But most important, take the first steps, do something, anything, that moves you forward with this project.
Then when you try this if it doesn't work, show your code and we'll be much better able to help.

Categories

Resources