Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Posts
    22
    Rep Power
    0

    Default I want set HEIGHT, WIDTH for Button

    Hello Everyone !!

    I want to know. How to: set Height and Width for a Button. I'm try width
    JButton b = new JButton("Button One");
    b.HEIGHT = 100;
    b.WIDTH = 200;

    or

    b.setSize(100,100);

    it's not work, build success

    I mean here is to the height and width of the button raised a little. Still do not know any other way?

    thank you

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    for setSize to work (or perhaps better, setBounds) the container that holds the JButton can be using no layout, in other words, it must have setLayout(null).

    Having said this, I don't recommend that you do this. Much better is to learn to use the various layout managers and let them size the JButton and other components for you.

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    And layout managers use setPreferredSize() as a hint, if you need to override the default size for some reason.

  4. #4
    Join Date
    Nov 2009
    Posts
    22
    Rep Power
    0

    Default

    thank you.
    Means I can only setSize the JButton when I setLayout = Null
    You also suggest that you research on how to control the size of the components by managing the size of the layout. You correctly.

    Thank

Similar Threads

  1. Using setBounds (x.y,width,height) constructor
    By hitmen in forum AWT / Swing
    Replies: 3
    Last Post: 03-06-2009, 01:12 PM
  2. Get Image Height and Width
    By neeraj.singh in forum AWT / Swing
    Replies: 10
    Last Post: 02-18-2009, 02:09 PM
  3. Replies: 4
    Last Post: 06-25-2008, 09:09 PM
  4. ComboBox Fix Width
    By Azndaddy in forum New To Java
    Replies: 2
    Last Post: 05-29-2008, 05:23 AM
  5. dynamising the height of a JPopupMenu
    By iimasd in forum AWT / Swing
    Replies: 6
    Last Post: 11-21-2007, 11:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •