Issue with JTextField not displaying correctly

I'm working on a school assignment creating a Social Media timeline. I'm working on the implementation of searching the time by specific user-specified things. My issue is when I am creating my JTextFields, they are not displaying with a width larger than 1 character.

Here is an example of how I am creating and adding the JTextField to a JPanel:

        JTextField hashtagField = new JTextField(20);
        hashtagField.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                hashtagField.setText("");
                hashtagField.removeFocusListener(this);
            }
        });
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.anchor = GridBagConstraints.LINE_END;
        hashtagPanel.add(new JLabel("Enter a hashtag: "), gbc);
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.anchor = GridBagConstraints.LINE_START;
        hashtagPanel.add(hashtagField, gbc);       
        actionsPanel.add(hashtagPanel, HASHTAG_ID);

I have tried to remove the FocusListener from the code, but that does not fix the issue.

Also, here is an example of what the code is producing:Output

EDIT: I noticed that changing the setResizable(boolean visibility) method's parameter to true fixes this, but I don't want to allow the user to resize the frame.



from Recent Questions - Stack Overflow https://ift.tt/34K2mvm
https://ift.tt/34GQHgT

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation