I am creating a GUI using BlueJ - Java, i have made the entry boxes however i cant seem to add a label to go either above each one or to the left. Could anyone help me out and tell me where im going wrong ? My code is below:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Log extends JFrame {
public static void main(String[] args){
Log frameTabel = new Log();
}
JButton Confirm = new JButton("Confirm");
JPanel panel = new JPanel();
JLabel label1 = new JLabel("Name", JLabel.RIGHT);
JTextField FullName = new JTextField(15);
JTextField Address1line = new JTextField(15);
JTextField postcode = new JTextField(15);
JTextField Destination = new JTextField(15);
JTextField Date = new JTextField(15);
JTextField MilesTravelling = new JTextField(15);
JLabel lblMsg = new JLabel ("Name",JLabel.LEFT);
Log(){
super("Customer GUI");
setSize(300,400);
setLocation(400,250);
panel.setLayout(null);
FullName.setBounds(70,30,150,20);
Address1line.setBounds(70,80,150,20);
postcode.setBounds(70,130,150,20);
Destination.setBounds(70,180,150,20);
Date.setBounds(70,230,150,20);
MilesTravelling.setBounds(70,280,150,20);
Confirm.setBounds(105,320,80,20);
panel.add(lblMsg);
panel.add(Confirm);
panel.add(FullName);
panel.add(Address1line);
panel.add(postcode);
panel.add(Destination);
panel.add(Date);
panel.add(MilesTravelling);
getContentPane().add(label1);
getContentPane().add(panel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
.
getContentPane().add(label1); //JFrames CENTER area
getContentPane().add(panel);
.
getContentPane().add(panel);
NullLayout
and Log frameTabel = new Log();
should be wrapped into invokeLater
(Swing GUI should be created and intialized on EventDispatchThread
), more to see in Oracle tutorial Initial Thread
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.