Results 1 to 10 of 10
Thread: Moving Components Around
- 12-12-2010, 05:56 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
Moving Components Around
I used to be a VisualBASIC programmer and it was pretty easy to move a command button around. All you had to do was specify a left and a top value in the code.
Ex:
cmdButton.Left = 50
cmdButton.Top = 100
Is there a way to do this with AWT buttons & other components as well?
P.S. Sorry for defiling this forum with VisualBASIC codes... LOL.
- 12-12-2010, 07:05 PM #2
In Java using AWT, or Swing UI components, components such as Buttons are laid out within a container, such as a Panel. The containers use a LayoutManager to have the button width and height and positional offset inside the container set for us. Most of the built-in to the Java VM layout managers don't let you tune the button individual X,Y coordinates that is.
Probably the most useful for fine tuning, and also the most compicated, is to use a GridBagLayout.
- 12-12-2010, 07:37 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
Gawd dammit. Why does it have to be difficult?
-
- 12-12-2010, 08:51 PM #5
Member
- Join Date
- Jan 2009
- Posts
- 8
- Rep Power
- 0
For JButtons, you have to set layout (if not CardLayout or similar function) to null and specify bounds for button like:
But if your container is resizeable, then button place stays same and container look degrades.Java Code:JButton button = new JButton("This is a button") button.setBounds(topX, topY, buttonWidth, buttonHeight);
-
I very strongly disagree with the statements above. Why do you recommend this over use of layout managers? With what experience do you base these recommendation on? What will happen if/when a GUI created with null layout is run in a different OS with different screen resolutions?
Agree, and not just in this situation, but in many other situations as well.But if your container is resizeable, then button place stays same and container look degrades.Last edited by Fubarable; 12-12-2010 at 09:11 PM.
- 12-12-2010, 09:14 PM #7
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
-
OP, again, while transhaydar means well, this recommendations will not work in the long run. I strongly urge you to read up on how to use layout managers if you want to learn to create flexible scalable Swing GUI's.
- 12-12-2010, 09:27 PM #9
Member
- Join Date
- Dec 2010
- Posts
- 6
- Rep Power
- 0
I don't think you understand what I'm trying to make here. It's never going to be a scaleable window. It's like a dialogue. It's only meant to be minimized and closed. Not scalable, not maximizable.
- 12-12-2010, 10:08 PM #10
Member
- Join Date
- Jan 2009
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
moving a pic, another pic disappears
By benjamin in forum New To JavaReplies: 4Last Post: 06-16-2010, 06:18 PM -
Moving objects
By rsjava24 in forum AWT / SwingReplies: 1Last Post: 02-26-2010, 10:47 AM -
moving square
By blindfolded in forum New To JavaReplies: 5Last Post: 01-22-2010, 05:58 PM -
moving a file
By swati.jyoti in forum New To JavaReplies: 8Last Post: 11-23-2009, 08:44 AM -
Moving Box
By anilanar in forum New To JavaReplies: 2Last Post: 08-30-2009, 12:29 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks