HI,
Code below for inserting labels and text boxes.
The text box "patientNameField " seems to be small when form is launched.Only same size of cursor. How to i make this wider. Also what is the best way to postion all the elements on form rather than using ".setbounds."
Code below for inserting labels and text boxes.
The text box "patientNameField " seems to be small when form is launched.Only same size of cursor. How to i make this wider. Also what is the best way to postion all the elements on form rather than using ".setbounds."
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.table.DefaultTableModel;
import javax.swing.border.TitledBorder;
class AddPatient
{
public static void main(String[] args)
{
{
//Set look and feel to NImbus.
try {
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels())
{
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception UnsupportedLookAndFeelException)
{
// If Nimbus is not available
UIManager.getSystemLookAndFeelClassName();
}
final JFrame frame = new JFrame("Add Patient form");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1024,768);
final JPanel addPatientgui = new JPanel(new BorderLayout(5,5));
addPatientgui.setBorder( new TitledBorder("Enter new patient details") );
JLabel lmain,ldi,lname,ladd,ltel,lspecial,ldid,ldspec,lwork,lworkfrom,lworkto,lfee;
JTextField patientNameField,tfname,tftel,tfdid,tfworkf,tfworkt,tffee;
TextArea taadd,tacur,taspecial;
// lmain = new JLabel("Patient Information");
//lmain.setBounds(440,35,107,15);
//addPatientgui.add(lmain);
ldi=new JLabel("Patient Information");
ldi.setBounds(40,70,120,15);
addPatientgui.add(ldi);
lname=new JLabel("Name :");
lname.setBounds(104,97,70,25);
addPatientgui.add(lname);
patientNameField = new JTextField();
patientNameField.setPreferredSize(new Dimension(70, 50));
patientNameField.setHorizontalAlignment(0);
patientNameField.setMaximumSize( patientNameField.getPreferredSize() );
addPatientgui.add(patientNameField);
patientNameField.setBounds(270,97,250,20);
ladd=new JLabel("Address :");
ladd.setBounds(104,138,70,15);
addPatientgui.add(ladd);
//taadd=new TextArea();
//taadd.setBounds(270,138,250,100);
//addPatientgui.add(taadd);
frame.setContentPane(addPatientgui);
// frame.pack(); /* window to be sized to fit the preferred size of its sub components */
// place window in center of screen
frame.setLocationRelativeTo(null);
try {
// 1.6+
frame.setLocationByPlatform(true);
frame.setMinimumSize(frame.getSize());
} catch(Throwable ignoreAndContinue) {
}
frame.setVisible(true);
}
}
}