Results 1 to 6 of 6
Like Tree3Likes
  • 1 Post By asifzbaig
  • 1 Post By Fubarable
  • 1 Post By Fubarable

Thread: My "form" is 9X uglier than a bag of butts (How to restrict the width of JTextField?)

  1. #1
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default My "form" is 9X uglier than a bag of butts (How to restrict the width of JTextField?)

    I'm using BorderLayout on my frame and BoxLayout on my panel:

    Java Code:
    frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
    This is working well enough, except that my JTextFields are the entire width of the panel (about 10X wider than they need to be). How can I get them to straighten up and fly right?

    Similarly, how can I add some "padding" or margins to my components, so that they don't scrunch right up against each other?

  2. #2
    asifzbaig is offline Member
    Join Date
    May 2011
    Posts
    56
    Rep Power
    0

    Default

    Try two things:
    Java Code:
    textField.setSize(int width, int height);
    and
    Java Code:
    textField.setResizable(false);
    blackbird likes this.

  3. #3
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    Quote Originally Posted by asifzbaig View Post
    Try two things:
    Java Code:
    textField.setSize(int width, int height);
    and
    Java Code:
    textField.setResizable(false);
    Thanks, but the first has no affect, and the second won't compile:

    "The method setResizable(boolean) is undefined for the type JTextField"

    Anybody else?

  4. #4
    blackbird is offline Senior Member
    Join Date
    Jul 2011
    Posts
    100
    Rep Power
    0

    Default

    The only thing I've found that does any good is to provide some space around the JLabels:

    Java Code:
    lblIPAddr.setPreferredSize(new Dimension(32, 32));

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

    Default

    I strongly disagree with asifzbaig's advice. The key is to use the right combinations of nested containers using the best layout managers for the situation at hand. To help you best I suggest you post three things:
    • An sscce that shows your current gui (please read the link).
    • An image of the current GUI
    • An image of the desired GUI layout

    With this we will be able to get a much better grasp of just what you're trying to do and how to help you achieve it.
    blackbird likes this.

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

Similar Threads

  1. Replies: 5
    Last Post: 07-13-2011, 02:25 PM
  2. Replies: 6
    Last Post: 11-19-2010, 07:44 PM
  3. Replies: 1
    Last Post: 01-21-2010, 09:20 AM
  4. Replies: 1
    Last Post: 10-20-2008, 07:35 AM
  5. "Displayed tab width" problem...
    By Petike in forum Eclipse
    Replies: 0
    Last Post: 03-17-2008, 09:39 PM

Posting Permissions

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