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.
Related
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 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 8 years ago.
Improve this question
Im pretty new to SWING and I tried my best but this is what is happening.
I have a interface that looks like this:
https://dl.dropboxusercontent.com/u/17524455/nodelete/1.jpg
From the main thread I call:
FrmMain.settextParticipants(5 + "");
FrmMain.setLaps(5 + "");
FrmMain.setRaceType("standard");
And that goes OK.
I Even manage to update the stoptime and time in the upper part of the GUI.
But as soon as I call (in the next line)
PnlRacers.PnlTransparents[0].setNameAndKartNr("01", "RACER");
My UI breaks like this:
https://dl.dropboxusercontent.com/u/17524455/nodelete/2.jpg
And the only thing that helps to fix the UI is, when I grab the window and move it around (to my second screen for example). That tells me that the "data" or "functions" are working well I guess... But the REDRAWING (or how to call it) is somehow ok for the first arguments and broken for the last class. After moving around it looks like this: https://dl.dropboxusercontent.com/u/17524455/nodelete/3.jpg
I read something about redraw() and validate() and I tried all on all places and on any element I was working with :(.
Maybe someone knows what the problem could be and if the source should be any help, here it is: https://dl.dropboxusercontent.com/u/17524455/nodelete/TEST.rar
Please help :) Im so lost ...
Have you tried calling repaint() to the content pane after the change you implemented?
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.
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
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