Results 1 to 8 of 8
Thread: JButton Size
- 10-13-2009, 01:24 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 56
- Rep Power
- 0
JButton Size
Hi,
I have a bit of trouble trying to enlarge the size of the button that I have on my JPanel or I should say I need to change the button size to a specific size:
Thanks,Java Code:.. .. .. JButton button = new JButton("OK"); button.setFont(new java.awt.Font("Arial", 1, 25)); add(button); .. .. ..
- 10-13-2009, 01:29 PM #2
Member
- Join Date
- Nov 2008
- Posts
- 67
- Rep Power
- 0
Use the setPreferredSize(Dimension preferredSize) method.
Example:
Java Code:int width=50; int height=40; button.setPreferredSize(new Dimension(width, height));
- 10-13-2009, 01:56 PM #3
Member
- Join Date
- Aug 2009
- Posts
- 56
- Rep Power
- 0
Thank you,
Also, I need to change te position of the button in the panel, I am not sure which method I should use to change the location of the button to a specific location?
- 10-13-2009, 03:17 PM #4
Try with this method for location.
setLocation
public void setLocation(int x,
int y)Moves this component to a new location. The top-left corner of the new location is specified by the x and y parameters in the coordinate space of this component's parent.
Parameters:
x - the x-coordinate of the new location's top-left corner in the parent's coordinate space
y - the y-coordinate of the new location's top-left corner in the parent's coordinate space
Since:
JDK1.1
See Also:
getLocation(), setBounds(int, int, int, int)
--------------------------------------------------------------------------------Ramya:cool:
- 10-13-2009, 05:04 PM #5
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Learn how to use Layout Managers to control the postion of components on a panel. Read the section from the Swing tutorial on "Using Layout Managers".
- 10-13-2009, 06:18 PM #6
- 10-14-2009, 07:54 AM #7
Member
- Join Date
- Aug 2009
- Posts
- 56
- Rep Power
- 0
Hi,
Thanks for the information, however none of the methods you mentioned seem to work for me, I have a button panel without any border inside the main panel. I tried a lot of methods but the button panel never moved to a different location within the main panel..Please tell me why this is happening..
- 10-14-2009, 04:20 PM #8
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
How can we tell you why this is happening? The examples from the Swing tutorials give you "working code". If it works in the tutorial, then obviously you didn't read the tutorial or try the demo code.Please tell me why this is happening..
If you need more help then post your SSCCE.
Similar Threads
-
How to set enabled my JButton...?
By mlibot in forum New To JavaReplies: 3Last Post: 10-13-2009, 11:24 AM -
Setting frame size to the size of an image
By Yoruichi in forum AWT / SwingReplies: 5Last Post: 04-22-2009, 04:37 PM -
Jbutton size
By mrvigneshmca in forum AWT / SwingReplies: 2Last Post: 03-18-2009, 03:51 PM -
Help with JButton
By geoffreybarwise in forum New To JavaReplies: 4Last Post: 05-21-2008, 10:48 AM -
Few action in one Jbutton
By kubiasty in forum New To JavaReplies: 0Last Post: 07-25-2007, 10:19 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks