Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: JButton Width & Height

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JButton Width & Height

    How do I set the width and height to a JButton using a (gridLayout) ?


  2. #2
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: JButton Width & Height

    you can use setSize or setBounds methods o JButton class

  3. #3
    Junior Member
    Join Date
    May 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JButton Width & Height

    :S

    Solved my own problem after looking a bit, maybe I shoulda waited before I posted this, but the simplest solution I found is:

    buttonName.setPreferredSize(new Dimension(ButtonWidth, ButtonHeight));

    i don't know how this works in other layouts, but in a gridLayout w/ panels etc. it works like a charm
    Last edited by Howdy_McGee; May 22nd, 2010 at 03:26 AM.

  4. #4
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: JButton Width & Height

    why not? have you checked it?

  5. #5
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: JButton Width & Height

    Quote Originally Posted by Howdy_McGee View Post
    i don't know how this works in other layouts, but in a gridLayout w/ panels etc. it works like a charm
    Most layouts respect the component preferred size. See Laying Out Components

Similar Threads

  1. Reading the size (height and width) of word documents
    By pradeep_das in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 7th, 2010, 10:58 AM
  2. JButton help
    By tabutcher in forum Java Applets
    Replies: 4
    Last Post: March 9th, 2010, 07:04 PM
  3. JButton Help
    By ravjot28 in forum AWT / Java Swing
    Replies: 3
    Last Post: January 17th, 2010, 11:38 AM
  4. JButton...
    By chronoz13 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 27th, 2009, 11:39 AM
  5. Getting table height using JSTL
    By jsnx7 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: March 19th, 2009, 01:03 PM