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 8481723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:38:10+00:00 2026-06-10T19:38:10+00:00

I’m working with a simple GUI and I’m having a hard time with my

  • 0

I’m working with a simple GUI and I’m having a hard time with my text fields.

enter image description here
This is what I’m working with. The one in the right is what it’s supposed to look like, and the left one is what I did. I’ve successfully put the labels Address 1, Address 2, etc. But when I started putting the text fields, it disappeared. I tried using the setSize, setLocation, but nothing works.

The same thing is happening to the upper panel “Paymen Method”, as seen in the expected outcome, there should be a text field. I have them in my codes but they’re not showing up when being run. Help please.

Here’s my codes:

    import javax.swing.*;
    import java.awt.*;
    public class PanelDemo extends javax.swing.JFrame{
    private static final int FRAME_WIDTH = 300;
    private static final int FRAME_HEIGHT = 350;
    private static final int FRAME_X_ORIGIN = 150;
    private static final int FRAME_Y_ORIGIN = 250;
    public static void main(String[] args){
    //Frame
    JFrame contentPane = new javax.swing.JFrame();
    contentPane.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    contentPane.setSize(300,350);
    contentPane.setResizable(false);
    contentPane.setLayout(new BorderLayout());
    //Payment Panel
    JPanel paymentPanel = new javax.swing.JPanel();
    paymentPanel.setLayout(new BorderLayout());
    //paymentPanel.setPreferredSize(new java.awt.Dimension(270, 90));
    paymentPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Payment Method", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12)));

    ////Components inside Payment Panel
    ////A) Panels: Radio and Details
    JPanel radioPanel = new JPanel();
    radioPanel.setLayout(new GridLayout(3,1));
    JRadioButton Rbutton1 = new JRadioButton("Credit Card");
    JRadioButton Rbutton2 = new JRadioButton("E-Funds");
    JRadioButton Rbutton3 = new JRadioButton("Check");
    Rbutton3.setSelected(true);
    ButtonGroup Bgroup = new ButtonGroup();
    Bgroup.add(Rbutton1);
    Bgroup.add(Rbutton2);
    Bgroup.add(Rbutton3);
    radioPanel.add(Rbutton1);
    radioPanel.add(Rbutton2);
    radioPanel.add(Rbutton3);

    //I thought of using a panel as a gap, but still didn't work
    /*JPanel gap = new JPanel();
    gap.setLayout(new BorderLayout());
    gap.setPreferredSize(new java.awt.Dimension(10, 90));*/


    JPanel detailsPanel = new JPanel();
    detailsPanel.setLayout(new GridLayout(2,1));
    //detailsPanel
    JLabel Accountnum = new JLabel("Account number:");
    JTextField Account = new JTextField();
    Account.setPreferredSize(new java.awt.Dimension(90, 40));
    detailsPanel.add(Accountnum);
    detailsPanel.add(Account);

    paymentPanel.add(gap, BorderLayout.CENTER);
    paymentPanel.add(detailsPanel);
    paymentPanel.add(radioPanel);
    contentPane.add(paymentPanel, BorderLayout.PAGE_START);

    ////Address Information Panel
    JPanel addressPanel = new JPanel();
    addressPanel.setLayout(new BorderLayout());
    addressPanel.setSize(new java.awt.Dimension(270, 80));
    addressPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Adress Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12)));
    contentPane.add(addressPanel, BorderLayout.CENTER);

    ////Components inside the Address Information Panel
    ////A) Labels (Address 1, Address 2,...)
    JPanel InfoLabel = new JPanel();
    InfoLabel.setLayout(new GridLayout(5,1));
    JLabel address1 = new JLabel("Address 1:");
    JLabel address2 = new JLabel("Address 2:");
    JLabel city = new JLabel("City:");
    JLabel state = new JLabel("State:");
    JLabel zip = new JLabel("Zip Code:");

    InfoLabel.add(address1);
    InfoLabel.add(address2);
    InfoLabel.add(city);
    InfoLabel.add(state);
    InfoLabel.add(zip);

    ////B)Text Fields
    JPanel infotext = new JPanel();
    infotext.setLayout(new GridLayout(5,1));

    JTextField text1 = new JTextField();
    JTextField text2 = new JTextField();
    JTextField text3 = new JTextField();
    JTextField text4 = new JTextField();
    JTextField text5 = new JTextField();

    addressPanel.add(InfoLabel);
    addressPanel.add(infotext);

    JPanel controlPanel = new JPanel(); 
    controlPanel.setLayout(new FlowLayout());
    JLabel test = new JLabel("test");
    controlPanel.add(test);
    contentPane.add(controlPanel, BorderLayout.PAGE_END);


    contentPane.setVisible(true);
}

}
  • 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-10T19:38:11+00:00Added an answer on June 10, 2026 at 7:38 pm

    I modified your code a little bit to get to a version that does what you need. Basically, all I did was cleaning the way you are using the layout managers. If you expect that you will have to do several such user interfaces then you could try to read the javadocs for the Swing layout managers in order to better understand them.

    Here is the working version:

    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    
    import javax.swing.ButtonGroup;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    import javax.swing.JTextField;
    
    public class PanelDemo extends javax.swing.JFrame {
      private static final int FRAME_WIDTH = 300;
      private static final int FRAME_HEIGHT = 350;
      private static final int FRAME_X_ORIGIN = 150;
      private static final int FRAME_Y_ORIGIN = 250;
    
      public static void main(String[] args) {
        // Frame
        JFrame contentPane = new javax.swing.JFrame();
        contentPane.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        contentPane.setSize(300, 350);
        contentPane.setResizable(false);
        contentPane.setLayout(new BorderLayout());
        // Payment Panel
        JPanel paymentPanel = new javax.swing.JPanel();
        paymentPanel.setLayout(new BorderLayout());
        // paymentPanel.setPreferredSize(new java.awt.Dimension(270, 90));
        paymentPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Payment Method",
            javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12)));
    
        // //Components inside Payment Panel
        // //A) Panels: Radio and Details
        JPanel radioPanel = new JPanel();
        radioPanel.setLayout(new GridLayout(3, 1));
        JRadioButton Rbutton1 = new JRadioButton("Credit Card");
        JRadioButton Rbutton2 = new JRadioButton("E-Funds");
        JRadioButton Rbutton3 = new JRadioButton("Check");
        Rbutton3.setSelected(true);
        ButtonGroup Bgroup = new ButtonGroup();
        Bgroup.add(Rbutton1);
        Bgroup.add(Rbutton2);
        Bgroup.add(Rbutton3);
        radioPanel.add(Rbutton1);
        radioPanel.add(Rbutton2);
        radioPanel.add(Rbutton3);
    
        // I thought of using a panel as a gap, but still didn't work
        /*
         * JPanel gap = new JPanel(); gap.setLayout(new BorderLayout());
         * gap.setPreferredSize(new java.awt.Dimension(10, 90));
         */
    
        JPanel detailsPanel = new JPanel();
        detailsPanel.setLayout(new GridLayout(2, 2));
        // detailsPanel
        JLabel Accountnum = new JLabel("Account number:");
        JTextField Account = new JTextField();
        Account.setPreferredSize(new java.awt.Dimension(90, 40));
        detailsPanel.add(Accountnum);
        detailsPanel.add(Account);
    
        // paymentPanel.add(gap, BorderLayout.CENTER);
        paymentPanel.add(radioPanel, BorderLayout.CENTER);
        paymentPanel.add(detailsPanel, BorderLayout.EAST);
        contentPane.add(paymentPanel, BorderLayout.PAGE_START);
    
        // //Address Information Panel
        JPanel addressPanel = new JPanel();
        addressPanel.setLayout(new BorderLayout());
        addressPanel.setSize(new java.awt.Dimension(270, 80));
        addressPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Adress Information",
            javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12)));
        contentPane.add(addressPanel, BorderLayout.CENTER);
    
        // //Components inside the Address Information Panel
        // //A) Labels (Address 1, Address 2,...)
        JPanel InfoLabel = new JPanel();
        InfoLabel.setLayout(new GridLayout(5, 2));
        JLabel address1 = new JLabel("Address 1:");
        JLabel address2 = new JLabel("Address 2:");
        JLabel city = new JLabel("City:");
        JLabel state = new JLabel("State:");
        JLabel zip = new JLabel("Zip Code:");
        JTextField text1 = new JTextField();
        JTextField text2 = new JTextField();
        JTextField text3 = new JTextField();
        JTextField text4 = new JTextField();
        JTextField text5 = new JTextField();
    
        InfoLabel.add(address1);
        InfoLabel.add(text1);
        InfoLabel.add(address2);
        InfoLabel.add(text2);
        InfoLabel.add(city);
        InfoLabel.add(text3);
        InfoLabel.add(state);
        InfoLabel.add(text4);
        InfoLabel.add(zip);
        InfoLabel.add(text5);
    
        // //B)Text Fields
        JPanel infotext = new JPanel();
        infotext.setLayout(new GridLayout(5, 1));
    
        addressPanel.add(InfoLabel, BorderLayout.CENTER);
    //    addressPanel.add(infotext);
    
        JPanel controlPanel = new JPanel();
        controlPanel.setLayout(new FlowLayout());
        JLabel test = new JLabel("test");
        controlPanel.add(test);
        contentPane.add(controlPanel, BorderLayout.PAGE_END);
        contentPane.setVisible(true);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace

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.