about buiding GUIs
Hey everyone,
I was working on small program for building GUIs,
the progam that I was working on has LIST and TEXTAREA and three buttons below them. Here is my problem:
I was trying to incorprate a scrolbar into the LIST,but somehow I am unable to achieve that because I am new to java, Can anyone tell me how I can achieve my goal ? here is the code developed so far :
Code:
code
import java.awt.*;
import java.awt.event.*;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.DefaultListModel;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
public class NurseSystem extends JFrame
{
public NurseSystem()
{
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenu editMenu = new JMenu("Edit");
//add sub menus
JMenuItem newFileItem = new JMenuItem("New");
JMenuItem openFileItem = new JMenuItem("open");
JMenuItem addFileItem = new JMenuItem("Add");
JMenuItem ModifyFileItem = new JMenuItem("Modify");
JMenuItem deleteFileItem = new JMenuItem("Delete");
//file submenu
fileMenu.add(newFileItem);
fileMenu.add(openFileItem);
//add edit submenu
editMenu.add(addFileItem);
editMenu.add(ModifyFileItem);
editMenu.add(deleteFileItem);
//Add the menus to the menubar
menuBar.add (fileMenu);
menuBar.add (editMenu);
//add the menubar to the application window
setJMenuBar (menuBar);
//Name and Detailed labels
JLabel label1 = new JLabel(" ");
JLabel label2 = new JLabel(" ");
JLabel nurseName = new JLabel("Nurse Name",JLabel.LEFT);
JLabel detailedInfo = new JLabel("Detailed Information");
//Create a LIst
//set component layout
FlowLayout layout = new FlowLayout();
Container mainWindow = getContentPane();
mainWindow.setLayout (layout);
//add labels to the main Window
mainWindow.add(nurseName);
mainWindow.add(label1);
mainWindow.add(label2);
mainWindow.add(detailedInfo);
this.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}
public static void main(String args[])
{
System.out.print("Nurse System");
NurseSystem f = new NurseSystem();
f.setSize(500,400);
f.show();
}
}
To add scroll bars to a control:
Code:
JTextArea textBox = new JTextArea();
JScrollPane myPane = newJScrollPane(textBox);