i have tried adding scrollpanes to the Textare but to no avail it cant Appear. i have initialised some text and added it ot the Textarea bt it dosent work.
Help me solve it lifesavers!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.lang.Object.*;
import javax.swing.border.*;
import java.awt.Toolkit;
import java.awt.Cursor;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.Cursor;
import java.text.*;
import java.sql.*;
import java.lang.Object.*;
import java.awt.Image.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.*;
import java.text.*;
import java.math.*;
import java.awt.BorderLayout;
import javax.swing.BorderFactory;
import javax.swing.JScrollPane;
public class search extends JFrame
{
private JTextField idtxt;
private JButton searchbtn;
private JButton allbtn;
JTextArea display;
private JButton exitbtn;
private JButton printbtn;
private JButton bckbtn;
private JButton delbtn;
private JLabel idlabel;
private JButton clear;
private JTextArea jTextArea1;
JScrollPane scroll;
public search()
{
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
int answer = JOptionPane.showConfirmDialog(null,
"<html><b>Are you sure you want to quit the PMS System ?",
"PMS Exit Confirmation",
JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.YES_OPTION)
{
System.exit(0);
}
}
}
);
String text = "So, naturalisfgfgfgfgfgfgfgfgfgfgfgffffffffffffffffffffffgfgfgfgfgfgfgfgfgfgfgfgfgfgfgts observe, a flea\n"
+ "Has smaller fle fgfdgdfgdfgdfgdfgdfgfdgfdgdfhgdfffffffffffffffffffgdfgddfgdfgdfgdfgdfgfdgfgfgs that on him prey;\n"
+ "And these have fgfgfgfgfgfgfgggggggggggggggfffffffffffffffffgggggggggggggggggggggfgsmaller still to bite 'em;\n"
+ "And so procfgggggggggggggggggggggggggggggggfffffffffffffffffffffffffffffffffffffffffgggggggggggggggggggggggggggeed ad infinitum.\n\n"
+ " --Jonathan Swift";
//construct components
idtxt = new JTextField (5);
idtxt.setBorder(BorderFactory.createLoweredBevelBorder());
searchbtn = new JButton ("Search");
allbtn = new JButton ("View All");
Container contentPane = getContentPane();
display = new JTextArea();
scroll = new JScrollPane(display);
display.setLineWrap(true);
//contentPane.add(scroll, BorderLayout.CENTER);
add(scroll,BorderLayout.LINE_START);
add(scroll,BorderLayout.LINE_END);
display.setText(text);
//==================================================================
exitbtn = new JButton ("Exit");
exitbtn.setIcon(new ImageIcon("icons/Exit.png"));
clear = new JButton ("Clear");
clear.setIcon(new ImageIcon("icons/clear.png"));
printbtn = new JButton ("Print");
printbtn.setIcon(new ImageIcon("icons/print.png"));
bckbtn = new JButton ("Back");
bckbtn.setIcon(new ImageIcon("icons/back.png"));
delbtn = new JButton ("Delete / Release");
idlabel = new JLabel ("Enter Prisoner ID:");
JLabel footer = new JLabel();
footer.setIcon(new ImageIcon("icons/header.png"));
add(footer);
footer.setBounds(-50,550,800,200);
JLabel header = new JLabel();
header.setIcon(new ImageIcon("icons/header6.png"));
add(header);
header.setBounds(-50,-130,800,200);
//set components properties
idtxt.setToolTipText ("Enter prisoner Id to search");
searchbtn.setToolTipText ("Search a single prisoner");
allbtn.setToolTipText ("Search All Prisoners");
exitbtn.setToolTipText ("Quit the PMS");
printbtn.setToolTipText ("Print Table");
bckbtn.setToolTipText ("back");
delbtn.setToolTipText ("Delete/Release a Prisoner");
//adjust size and set layout
setTitle("Prison Management System");
setIconImage (getToolkit().getImage ("icons/logo.png"));
setPreferredSize (new Dimension (753, 616));
setLayout (null);
//add components
add (idtxt);
add (searchbtn);
add (allbtn);
add (display);
add (exitbtn);
add (printbtn);
add (bckbtn);
add (delbtn);
add (idlabel);
add (clear);
//set component bounds (only needed by Absolute Positioning)
idtxt.setBounds (135, 110, 165, 25);
searchbtn.setBounds (320, 110, 75, 25);
allbtn.setBounds (420, 110, 85, 25);
display.setBounds (25, 155, 705, 365);
exitbtn.setBounds (565, 525, 100, 25);
clear.setBounds (440, 525, 100, 25);
printbtn.setBounds (340, 525, 100, 25);
bckbtn.setBounds (205, 525, 100, 25);
delbtn.setBounds (545, 110, 135, 25);
idlabel.setBounds (20, 110, 110, 25);
ButtonHandler Handler = new ButtonHandler();
searchbtn.addActionListener(Handler);
allbtn.addActionListener(Handler);
printbtn.addActionListener(Handler);
exitbtn.addActionListener(Handler);
bckbtn.addActionListener(Handler);
delbtn.addActionListener(Handler);
clear.addActionListener(Handler);
}
public class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == searchbtn)
{
dispose();
}
else if(e.getSource() == allbtn)
{
dispose();
}
else if(e.getSource() == printbtn)
{
JOptionPane.showMessageDialog(null," To handle print jobs!");
}
else if(e.getSource() == delbtn)
{
JOptionPane.showMessageDialog(null," To clears the componets!");
}
else if(e.getSource() == bckbtn)
{
dispose();
}
else if(e.getSource() == clear)
{
display.setText("");
display.setText("");
}
else if(e.getSource() == exitbtn )
{
if (JOptionPane.showConfirmDialog(new JFrame(),
"<html><b>Are you sure you want to quit the PMS System ?",
"PMS Exit Confirmation",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
System.exit(0);
}
}
}
public static void main (String[] args)
{
search frame = new search ();
frame.setDefaultCloseOperation (JFrame.DO_NOTHING_ON_CLOSE);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible (true);
}
}