Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By jim829

Thread: jbuttons

  1. #1
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    100
    Rep Power
    0

    Post jbuttons

    hello i am working on a project where i can use my own buttons (an image with a rectangle behind it) then check if mouseclick intersects that rectangle but i want to do it the best way possible and use javas full built in functionality.

    basically i want a jframe with 1200 width, and the first 160 pixels is a place where i can have a menu with buttons, names, descriptions etc. then the rest of the 1040px is a place where i can have an image and 2d programming / images / animation.

    i have a picture example that i will try to include below

    jbuttons-gameareaandinformationbar.png

    as you should see in the image, there is a panel for buttons and a panel for the game.

    i was thinking about a couple ways i could do this,

    #1 use one jframe (do the buttons myself) so i can set x, y position (very important that i can set x, y position of the buttons / text / container in the menu bar (gridbaglayout?)

    #2 try a gridbaglayout and buttons inside that (but i need to set the x, y position)

    #3 have two jpanels in the jframe, although i am more used to one jpanel and i dont want it to get too complicated and have problems with my game area cause i already figured out how to do that.

    #4 search google for ways to set jbuttons at a fixed position in the jframe like i can with g2d.drawimage(55, 55, 50, 50); (perhaps i would stumble on this example with an example of gridbaglayout or something similar (flowlayout, etc.)

    thank you for reading,

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: jbuttons

    So, you want to have rectangular JButtons at specific locations in your JFrame?

    You could use a null layout and absolute positioning (google keywords for you), but that's only if you know the window will never be resized.

    You could also do the painting yourself, but then like you said you'd have to detect the clicks yourself. Not super hard if you know where you're drawing the buttons.

    Which approach you take depends on your context. Maybe try out both and see which makes more sense to you!
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    100
    Rep Power
    0

    Default Re: jbuttons

    yes right now i am going "null layout" / absolute positioing although i do have to admit setting variables and objects to null gets me a little worried.

    edit: i want the jbuttons methods / functionality because they were made for the stuff that im doing

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,384
    Rep Power
    5

    Default Re: jbuttons

    You received two responses from an earlier post and have yet to acknowledge them. See --> using paintcomponent to draw over a jbutton. Folks are more likely to respond to future posts if you kindly respond to the earlier answers before posting other questions.

    Regards,
    Jim
    natdizzle likes this.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    100
    Rep Power
    0

    Default Re: jbuttons

    OKAY i went ahead and set layoutmanager to null and setbounds on the button i think i am good to go.

    although if anyone knows how to do this without using "null" let me know.

    thank you,

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: jbuttons

    Using a null layout is only "bad" because people overuse it when they really should be using a layout manager. Layout managers help with things like resizing and repositioning components, so most displays really should be using them.

    However, it seems like you actually do have a case where using a null layout is the right way to go, as long as your window can't be resized.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: jbuttons

    If you are just trying to get JButtons on the left side of your JFrame, add the buttons to a JPanel, add the JPanel to BorderLayout.WEST, then add the rest to another JPanel constrained to BorderLayout.CENTER

  8. #8
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    100
    Rep Power
    0

Similar Threads

  1. jbuttons
    By sarah jain in forum AWT / Swing
    Replies: 3
    Last Post: 03-16-2011, 07:13 AM
  2. Please help!JButtons
    By fourpixel in forum AWT / Swing
    Replies: 6
    Last Post: 09-29-2010, 01:48 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

Tags for this Thread

Posting Permissions

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