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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:17:06+00:00 2026-06-12T12:17:06+00:00

I am trying to create a form manually with code rather than the designer,

  • 0

I am trying to create a form manually with code rather than the designer, I have already created using the designer.

enter image description here

This is the manual code that I came up with so far but I am having problem aligning the label and textfield side by side

mport java.awt.*;
import javax.swing.*;
/**
 *
 * @author jackandjill
 */
public class summinup_copy extends JFrame
{
    private JLabel lblTitle, lblOctal, lblDecimal, lblMessage ;

private JTextField txtOctal, txtDecimal;

private JButton calculate_btn;




public  summinup_copy()       

{

JPanel panel = (JPanel)this.getContentPane();

panel.setLayout(new BorderLayout());

JPanel panCentre = new JPanel();

panCentre.setLayout(new GridLayout(3,3));

lblTitle = new JLabel("Area of Triangle");

lblTitle.setFont(new Font("Arial", 1, 20));

lblTitle.setHorizontalAlignment(JLabel.CENTER);

lblOctal = new JLabel("Octal");

lblOctal.setHorizontalAlignment(JLabel.CENTER) ;

//lblDecimal = new JLabel("Decimal");
//
//lblDecimal.setHorizontalAlignment(JLabel.CENTER);

lblMessage = new JLabel("Result will be displayed here");

lblMessage.setForeground(Color.red);

lblMessage.setHorizontalAlignment(JLabel.CENTER);

txtOctal = new JTextField("0", 5);

txtOctal.setHorizontalAlignment(JLabel.CENTER); 
//txtDecimal = new JTextField("0", 5);
//
//txtDecimal.setHorizontalAlignment(JLabel.CENTER);

calculate_btn = new JButton("Calculate Area");



//AHandlerClass aListener = new AHandlerClass() ;

//btnOtoD.addActionListener(aListener);

//btnDtoO.addActionListener(aListener);

panCentre.add(lblOctal);

//panCentre.add(lblDecimal);

panCentre.add(txtOctal);

//panCentre.add(txtDecimal);

panCentre.add(calculate_btn);

//panCentre.add(btnDtoO);

panel.add(lblTitle, BorderLayout.NORTH);

panel.add(lblMessage,BorderLayout.SOUTH);


panel.add(panCentre, BorderLayout.CENTER);

}

public static void main(String args[]) {

summinup_copy myGui = new summinup_copy();

myGui.setTitle("Bharath");

myGui.setSize(400, 200);

myGui.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-12T12:17:08+00:00Added an answer on June 12, 2026 at 12:17 pm

    As you have already figured out, you have to use LayoutManagers when coding a Swing GUI by hand. Here are some links that can help you figure out which LayoutManager is appropriate for a given look:

    http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html

    http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html

    In order to place a JLabel next to a JTextField or other component, I usually use GridLayout or GridBagLayout. I find that it takes a lot of trial and error trying to get components to look the way I want. Often you have to have layers of embedded JPanels to get it just right.

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

Sidebar

Related Questions

Using C#, I'm trying to create a form with a dataGridView that shows the
This code inside a JFrame form created in netbeans works fine as i'm trying
I am trying to create a form in Sharepoint using C#. I don't know
I am trying to create a form using only JavaScript. I mean create a
I'm trying to create a form that based on the users input would determine
I'm trying to create a form that clients would complete via the web, so
I am new to zend. I am trying to create login form using zend
I'm trying to create a custom form input that utilizes some images, it should
I am trying to create a user form that will allow the user to
I'm trying to create an editable page in Sharepoint. I already have the page

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.