Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:30:22+00:00 2026-06-17T06:30:22+00:00

I have added a JTextField to a JPanel using the Window Builder in Eclipse

  • 0

I have added a JTextField to a JPanel using the Window Builder in Eclipse and no matter what I tried, the text field is displayed like this:

ScreenShot
(source: gyazo.com)

I have tried to change the preferred size, the maximum and minimum sizes and it still appears like this.

How do I fix this? What have I done wrong?

Thanks in advance.

UPDATE


Code: (it is all automatically generated by Google’s Window Builder)

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import java.awt.Dimension;


public class Main extends JFrame {

private JPanel contentPane;
private JTextField textField;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Main frame = new Main();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);

    textField = new JTextField();
    textField.setSize(new Dimension(6, 3));
    textField.setMinimumSize(new Dimension(6, 5));
    textField.setMaximumSize(new Dimension(6, 3));
    textField.setPreferredSize(new Dimension(6, 3));
    contentPane.add(textField, BorderLayout.WEST);
    textField.setColumns(10);
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:30:24+00:00Added an answer on June 17, 2026 at 6:30 am

    You could simply use the default layout manager FlowLayout for the JPanel contentPane. This will respect the components preferred size:

    Remove (or comment out):

    contentPane.setLayout(new BorderLayout(0, 0));
    

    Always better to use a layout manager and avoid calling the setXXXSize methods for components for sizing. You can override getPreferredSize if necessary.

    See: Doing Without a Layout Manager

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a text field which extends javax.swing.JTextField and also have document listener like this
I have added an extra field Specification in Catalog->Product->Data tab. This text is stored
I am using eclipse and I have two TextField such that one text field
I have a class which extends JPanel, inside this panel i have added a
I have a JDialog which contains JPanel and other elements like JTextField . I
I got a JTextField , and to that field I have added a Keylistener
My text Field is not being added to my Jframe, I want to have
I have added the sdk files like dropbox website says, but I can't figure
I have JTextPane on my window and i have JTextField. When i press enter
I have added to a JTextField a JPopupMenu. Unfortunatelly, when i change the focus

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.