Results 1 to 7 of 7
- 04-09-2012, 12:10 PM #1
Senior Member
- Join Date
- Jan 2011
- Location
- Rizal Province, Philippiines
- Posts
- 167
- Rep Power
- 0
Hi how can I get the size of the JButton!! Help!!
HI IS ANY KNOWS HOW TO GET CURRENT SIZE OF THE JBUTTON, IM USING LAYOUT MANAGER I TRY TO CALL THE getSize(), getHeight(), getBounds() but none of these are working for me all the output is zero..
Please i need your help...
HERES THE OUTPUT IN THE TERMINE CONSOLE:Java Code:panel1 = new JPanel(new GridLayout(1,1,10,10)); btnAdd = new JButton("Add Student Info"); GridBagConstraints cst = new GridBagConstraints(); panel1.add(btnAdd); System.out.println(btnAdd.getSize()); System.out.println(btnAdd.getHeight()); System.out.println(btnAdd.getBounds()); getContentPane().add(panel1); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-475)/2, (screenSize.height-354)/2, 475, 354);
java.awt.Dimension[width=0,height=0]
0
java.awt.Rectangle[x=0,y=0,width=0,height=0]
- 04-09-2012, 12:17 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
Re: Hi how can I get the size of the JButton!! Help!!
As long as the JButton (or any Component for that matter) isn't visible it doesn't have a size or position ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-11-2012, 04:58 AM #3
Senior Member
- Join Date
- Jan 2011
- Location
- Rizal Province, Philippiines
- Posts
- 167
- Rep Power
- 0
Re: Hi how can I get the size of the JButton!! Help!!
It is visible, when I run it I can see the frame with jbuttons.
In my main method:
Java Code:public static void main(String[]args){ MyButtonDemo btnDemo = MyButtonDemo(); btnDemo.setDefaultCloseOperation(EXIT_ON_CLOSE); btnDemo.setBounds(0,0,350,350); btnDemo.setVisible(); }
- 04-11-2012, 07:06 AM #4
- 04-12-2012, 12:57 AM #5
Senior Member
- Join Date
- Jan 2011
- Location
- Rizal Province, Philippiines
- Posts
- 167
- Rep Power
- 0
- 04-12-2012, 01:18 AM #6
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
Re: Hi how can I get the size of the JButton!! Help!!
Get the size of the button after calling pack() on the parent JFrame, or making the JFrame visible - which will layout your components using the LayoutManagers and allow you to get the initial size.
- 04-12-2012, 04:19 AM #7
Re: Hi how can I get the size of the JButton!! Help!!
Why do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
ActionListener for JButton after changing Button to JButton
By ravi.joshi53 in forum Java AppletsReplies: 2Last Post: 10-07-2011, 07:35 AM -
JButton Size Help?
By bpx95 in forum New To JavaReplies: 1Last Post: 05-14-2011, 07:02 AM -
JButton Size
By jboy in forum New To JavaReplies: 7Last Post: 10-14-2009, 04:20 PM -
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


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks