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:
Java Code: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
and then using object.setBounds() to place it? I like that, but I'll take your advice and study up on layout managers also, I just wanted to have implicit control if I wanted it.Java Code:setLayout(null)
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
setIcon(...)
db
- 08-18-2009, 06:21 AM #5
Similar Threads
-
Help placing images in JFrame
By gammaman in forum New To JavaReplies: 8Last Post: 07-24-2009, 02:19 AM -
Placing Files In Folder
By ramesh.8189 in forum New To JavaReplies: 0Last Post: 02-06-2009, 12:36 PM -
Help with JButtons...
By ashton in forum New To JavaReplies: 8Last Post: 01-26-2009, 09:38 AM -
JButtons
By jadaleus in forum Advanced JavaReplies: 4Last Post: 10-17-2008, 02:49 AM -
JButtons
By fgasimzade in forum SWT / JFaceReplies: 1Last Post: 12-25-2007, 05:39 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks