Solved

Some help with look and fell in GUI

Posted on 2009-05-18
3
163 Views
Last Modified: 2012-05-07
Look at my picutre.

I would like the textfields to just be one row. So you got the label....then a textfield after that. Not a 3 line textfield (or how much it is)

I also would like to add to buttons at the botten.... Registrate and Cancle.

How do I do this?
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
 
 
 
 
 
public class Registrera extends JFrame {
 
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JFrame thisFrame;
	private Container c;
	private JPanel controlPanel=new JPanel();
	JTextField userNameField = new JTextField("");
	JTextField passwordField = new JPasswordField("");
	JTextField adressField = new JTextField("");
	JTextField nameField = new JTextField("");
	JTextField teleField = new JTextField("");
	JTextField pnrField = new JTextField("");
	
	Registrera() {
	      getRegi();
 
	    }
 
	    public void getRegi() {
	      JPanel connectionPanel;
	      JLabel nameLabel = new JLabel("Name:", JLabel.RIGHT);     
	      JLabel userNameLabel = new JLabel("User Name:", JLabel.RIGHT); 
	      JLabel pnrLabel = new JLabel("Personnummer:", JLabel.RIGHT); 
	      JLabel adressLabel = new JLabel("Adress:", JLabel.RIGHT);
	      JLabel teleLabel = new JLabel("Telefon:", JLabel.RIGHT);
	      JLabel passwordLabel = new JLabel("Password:", JLabel.RIGHT);      
	      
	      connectionPanel = new JPanel(false);
	      connectionPanel.setLayout(new BoxLayout(connectionPanel, BoxLayout.X_AXIS));
	      
	      JPanel namePanel = new JPanel(false);
	      namePanel.setLayout(new GridLayout(0, 1));
	      namePanel.add(nameLabel);
	      namePanel.add(adressLabel);
	      namePanel.add(pnrLabel);
	      namePanel.add(teleLabel);
	      namePanel.add(userNameLabel);
	      namePanel.add(passwordLabel);
	      
	      JPanel fieldPanel = new JPanel(false);
	      fieldPanel.setLayout(new GridLayout(0, 1));
	      fieldPanel.add(nameField);
	      fieldPanel.add(adressField);
	      fieldPanel.add(pnrField);
	      fieldPanel.add(teleField);
	      fieldPanel.add(userNameField);
	      fieldPanel.add(passwordField);
	      
	      connectionPanel.add(namePanel);
	      connectionPanel.add(fieldPanel);
	      
	      thisFrame = this;
	      thisFrame.setSize(500,500);
	      this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	      c = getContentPane();
	
	      
	      this.add(controlPanel, BorderLayout.SOUTH);        
	      c.add( connectionPanel ) ;
	      this.setVisible(true);
	      
	    }
	
}

Open in new window

Unavngivet.bmp
0
Comment
Question by:Mickeys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 26

Expert Comment

by:ksivananth
ID: 24410119
try this,

public class Registrera extends JFrame {
      
      /**
       *
       */
      private static final long serialVersionUID = 1L;
      private JFrame thisFrame;
      private Container c;
      private JPanel controlPanel=new JPanel();
      JTextField userNameField = new JTextField("", 10 );
      JTextField passwordField = new JPasswordField("", 10 );
      JTextField adressField = new JPasswordField("", 10 );
      JTextField nameField = new JPasswordField("", 10 );
      JTextField teleField = new JPasswordField("", 10 );
      JTextField pnrField = new JPasswordField("", 10 );
      
      Registrera() {
            getRegi();
 
          }
 
          public void getRegi() {
            JPanel connectionPanel;
            JLabel nameLabel = new JLabel("Name:", JLabel.RIGHT);    
            JLabel userNameLabel = new JLabel("User Name:", JLabel.RIGHT);
            JLabel pnrLabel = new JLabel("Personnummer:", JLabel.RIGHT);
            JLabel adressLabel = new JLabel("Adress:", JLabel.RIGHT);
            JLabel teleLabel = new JLabel("Telefon:", JLabel.RIGHT);
            JLabel passwordLabel = new JLabel("Password:", JLabel.RIGHT);      
            
            connectionPanel = new JPanel(false);
            connectionPanel.setLayout(new BoxLayout(connectionPanel, BoxLayout.X_AXIS));
            
            JPanel namePanel = new JPanel(false);
            namePanel.setLayout(new GridLayout(0, 1));
            namePanel.add(nameLabel);
            namePanel.add(adressLabel);
            namePanel.add(pnrLabel);
            namePanel.add(teleLabel);
            namePanel.add(userNameLabel);
            namePanel.add(passwordLabel);
            
            JPanel fieldPanel = new JPanel(false);
            fieldPanel.setLayout(new GridLayout(0, 1));
            fieldPanel.add(nameField);
            fieldPanel.add(adressField);
            fieldPanel.add(pnrField);
            fieldPanel.add(teleField);
            fieldPanel.add(userNameField);
            fieldPanel.add(passwordField);
            
            connectionPanel.add(namePanel);
            connectionPanel.add(fieldPanel);
            
            thisFrame = this;
//            thisFrame.setSize(500,500);
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
            c = getContentPane();
      
            
            this.add(controlPanel, BorderLayout.SOUTH);        
 
            c.add( connectionPanel, BorderLayout.NORTH ) ;
            thisFrame.pack() ;
            this.setVisible(true);
            
          }
}
0
 

Author Comment

by:Mickeys
ID: 24410136
That worked.....just the button as well. I want two buttons at the end

Registrate      Cancel

Do you have an answer for that aswell?
0
 
LVL 26

Accepted Solution

by:
ksivananth earned 500 total points
ID: 24410147
try this, copy beofre this.add(controlPanel, BorderLayout.SOUTH);        

      
            controlPanel.add( new JButton( "Registration" ) ) ;
            controlPanel.add( new JButton( "Cancel" ) ) ;
            
            
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SHA2 certs for IIS AND Java? 2 136
jsp login check 12 66
Bot application - advice 3 80
Tagging and Merging on Branch 1 68
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question