Results 1 to 8 of 8
- 12-31-2013, 05:36 PM #1
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
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,
- 12-31-2013, 05:53 PM #2
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!
- 12-31-2013, 06:55 PM #3
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
- 12-31-2013, 07:01 PM #4Senior Member
- Join Date
- Jan 2013
- Northern Virginia, United States
- Rep Power
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.
- 12-31-2013, 08:49 PM #5
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.
- 12-31-2013, 08:57 PM #6
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.
- 12-31-2013, 10:21 PM #7▼ dafuq did I do?
- Join Date
- Dec 2013
- Rep Power
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
- 12-31-2013, 11:59 PM #8
yes the frame will not be resizable
- By sarah jain in forum AWT / SwingReplies: 3Last Post: 03-16-2011, 08:13 AM
- By fourpixel in forum AWT / SwingReplies: 6Last Post: 09-29-2010, 01:48 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