Results 1 to 5 of 5
  1. #1
    v1nsai's Avatar
    v1nsai is offline Member
    Join Date
    Mar 2009
    Posts
    28
    Rep Power
    0

    Default 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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  3. #3
    v1nsai's Avatar
    v1nsai is offline Member
    Join Date
    Mar 2009
    Posts
    28
    Rep Power
    0

    Default

    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
    Java Code:
    setLayout(null)
    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.

    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

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default

    setIcon(...)

    db

  5. #5
    v1nsai's Avatar
    v1nsai is offline Member
    Join Date
    Mar 2009
    Posts
    28
    Rep Power
    0

    Default

    -_- thank you, I still hadn't phrased it properly to find it on google. I knew it was something I should know
    C:\DOS > C:\DOS.RUN > RUN.DOS.RUN

Similar Threads

  1. Help placing images in JFrame
    By gammaman in forum New To Java
    Replies: 8
    Last Post: 07-24-2009, 02:19 AM
  2. Placing Files In Folder
    By ramesh.8189 in forum New To Java
    Replies: 0
    Last Post: 02-06-2009, 12:36 PM
  3. Help with JButtons...
    By ashton in forum New To Java
    Replies: 8
    Last Post: 01-26-2009, 09:38 AM
  4. JButtons
    By jadaleus in forum Advanced Java
    Replies: 4
    Last Post: 10-17-2008, 02:49 AM
  5. JButtons
    By fgasimzade in forum SWT / JFace
    Replies: 1
    Last Post: 12-25-2007, 05:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •