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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:56:45+00:00 2026-05-27T13:56:45+00:00

MainClass(){ JFrame main = new JFrame(Login Form ); main.setBounds(350,150,500,500); main.setVisible(true); main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); name = new

  • 0
MainClass(){
    JFrame main = new JFrame("Login Form ");
    main.setBounds(350,150,500,500);
    main.setVisible(true);
    main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    name = new JTextField(10);
    pass = new JTextField(10);
    main.setLayout(new GridLayout(0,1));
    JPanel pane = new JPanel();
    main.add(pane);
    main.add(new JLabel("Username: "));
    pane.add(name);
    //main.add(pane);
    pane.add(new JLabel("Password: "));
    pane.add(pass);
    submit = new JButton("Submit");
    pane.add(submit);
    submit.addActionListener(new Handler());
}

I want to separate the text boxes in separate lines after the label username and name text box. I need to control the cursor to a new line.

  • 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-05-27T13:56:46+00:00Added an answer on May 27, 2026 at 1:56 pm

    i want to separate the text boxes in separate lines

    Layout

    import java.awt.*;
    import javax.swing.*;
    
    class MainClass {
    
        JTextField name;
        // This should be a JPasswordField!
        JTextField pass;
        JButton submit;
    
        MainClass(){
            JFrame main = new JFrame("Login Form ");
            // Don't use this nonsense!
            //main.setBounds(350,150,500,500);
            main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            name = new JTextField(10);
            pass = new JTextField(10);
            main.setLayout(new GridLayout(0,1));
            JPanel pane = new JPanel(new GridLayout(0,1));
            main.add(pane);
            pane.add(new JLabel("Username: "));
            pane.add(name);
            pane.add(new JLabel("Password: "));
            pane.add(pass);
            submit = new JButton("Submit");
            pane.add(submit);
            //submit.addActionListener(new Handler());
            main.pack();
            main.setVisible(true);
        }
    
        public static void main(String[] args) {
            MainClass mc = new MainClass();
        }
    }
    

    If I was building a login screen, it might be laid out more along these lines (with the labels right justified and the button in it’s own panel – left as an exercise for the reader).

    Log-In frame

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.EmptyBorder;
    
    class MainClass {
    
        JTextField name;
        JPasswordField pass;
        JButton submit;
    
        MainClass(){
            JFrame main = new JFrame("Login Form ");
            main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            name = new JTextField(10);
            pass = new JPasswordField(10);
    
            JPanel gui = new JPanel(new BorderLayout(3,3));
            gui.setBorder(new EmptyBorder(5,5,5,5));
            main.setContentPane(gui);
    
            JPanel labels = new JPanel(new GridLayout(0,1));
            JPanel controls = new JPanel(new GridLayout(0,1));
            gui.add(labels, BorderLayout.WEST);
            gui.add(controls, BorderLayout.CENTER);
    
            labels.add(new JLabel("Username: "));
            controls.add(name);
            labels.add(new JLabel("Password: "));
            controls.add(pass);
            submit = new JButton("Submit");
    
            gui.add(submit, BorderLayout.SOUTH);
            main.pack();
            main.setVisible(true);
        }
    
        public static void main(String[] args) {
            MainClass mc = new MainClass();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my main class code: public static void main(String[] args) { JFrame f=
I have a JFrame that is the main class of the program. I want
Let's assume I have the following code: public class MainClass { public static void
Is it possible to access a parent member in a child class... class MainClass
Is it OK to reference this when initializing a field? public class MainClass {
First I want to describe my situation briefly. I have two classes, one MainClass
I have a main class in a program that launches another class that handles
I have a small Java test app in Netbeans where the main() class reads
I subclassed UIScrollView Then created an object of it in the main class. Added
I am trying to run a function of the main class, but even with

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.