Results 1 to 5 of 5
- 08-16-2009, 03:47 AM #1
placing JButtons with x and y coords (possible?)
I've been reading through the API spec but I don't see a way to place JButtons without using SwingConstants, is there a way I can call it with an 'x,y' coordinate? Hell, is it possible to do is with JLabel, JTextField or any of the other classes that inherit from swing.component?
Also, in a completely unrelated question I can't remember how to change an Icon. I have this:
Icon arrowRight = new ImageIcon( "arrowRight.png" ); Icon direction = newImageIcon( "question.png" ); [B]Icon direction = arrowRight?[/B]
Last edited by v1nsai; 08-16-2009 at 03:59 AM.C:\DOS > C:\DOS.RUN > RUN.DOS.RUN
You can set the absolute position of buttons, labels, etc via a null layout. If you do this, you are responsible for not only the placement of the components but also their sizes, and this can be done with one shot via the Component method setBounds(int x, int y, int width, int height).
Having said this, I recommend against doing it if possible. Instead study the layout managers such as BorderLayout, BoxLayout, GridLayout and GridBagLayout and place your components using nested containers that use the best layout manager.
If you show a picture of what you are trying to achieve, we can likely give you more specific and helpful help.
- 08-16-2009, 07:57 PM #3
I'm actually writing a program to mess with my cousin, I was teaching her how to drive and she was freaking out and couldn't remember left from right so I'm writing something that will display an arrow pointing left or right, and buttons that you can click that say left and right.
So by null layout do you mean something like
I took a class on Java last semester that taught really advanced things like inheritence and polymorphism but spent hardly any time at all on GUI design, which is integral in my opinion. I feel like I have a lot of holes in my understanding.
What about redefining Icons? My compiler is not helping me figure it out and I know it's simple but I just can't bring it to mind.
Last edited by v1nsai; 08-16-2009 at 08:14 PM.C:\DOS > C:\DOS.RUN > RUN.DOS.RUN
- 08-17-2009, 09:16 AM #4
- 08-18-2009, 06:21 AM #5
- By gammaman in forum New To JavaReplies: 8Last Post: 07-24-2009, 02:19 AM
- By ramesh.8189 in forum New To JavaReplies: 0Last Post: 02-06-2009, 01:36 PM
- By ashton in forum New To JavaReplies: 8Last Post: 01-26-2009, 10:38 AM
- By jadaleus in forum Advanced JavaReplies: 4Last Post: 10-17-2008, 02:49 AM
- By fgasimzade in forum SWT / JFaceReplies: 1Last Post: 12-25-2007, 06:39 AM