Java TextArea and ScrollPane

The ScrollPane overlaps the TextArea



package ProjSuperMarket.objectClass;

import java.awt.Color;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.BorderFactory;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class AddProduct implements ActionListener{
private JPanel jpAdd;
private JLabel[] jlPRec;
private JTextField[] jtfPRec;
private ProductInfo[] pRec;
private JButton jbAdd, jbClear;
private JScrollPane jsp1, jsp2;
private JTextArea pProductList, pTransList;

public AddProduct(ProductInfo[] pRec){
jpAdd = new JPanel();
jlPRec = new JLabel[4];
jtfPRec = new JTextField[4];
String[] jlCaption = {"Product ID: ", "Product Name: ", "Product Brand: ", "Quantity: "};
for(int i = 0; i < jlPRec.length ; i++){
jlPRec[i] = new JLabel(jlCaption[i]);
jtfPRec[i] = new JTextField();
}
jsp1 = new JScrollPane(pProductList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jsp2 = new JScrollPane(pTransList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jbAdd = new JButton("Add");
jbClear = new JButton("Clear");
this.pRec = pRec;
pProductList = new JTextArea("Product List: ");
pTransList = new JTextArea("Trans List: ");

}
public void setAddProduct(){
//JLabel Alignment
jpAdd.setLayout(null);
jlPRec[0].setBounds(35,20,100,100);//Product ID:
jlPRec[1].setBounds(30,70,100,100);//Product Name;
jlPRec[2].setBounds(30,117,100,100);//Product Brand;
jlPRec[3].setBounds(35,165,100,100);//Quantity:
//JTextField Alignment
jtfPRec[0].setBounds(120,50,100,40); //Product ID:
jtfPRec[1].setBounds(120,100,100,40); //Product Name;
jtfPRec[2].setBounds(120,150,100,40); //Product Brand;
jtfPRec[3].setBounds(120,200,100,40); //Quantity:
for(int i = 0; i < jlPRec.length; i++){
jpAdd.add(jlPRec[i]);
jpAdd.add(jtfPRec[i]);
}
jpAdd.setBounds(0,0,500,600);
jbAdd.setBounds(30,250,80,40);
jbClear.setBounds(120,250,80,40);
jsp1.setBounds(225,50,160,250);
pProductList.setBounds(225,50,160,250);
pTransList.setBounds(400,50,160,250);
//jsp1.setVisible(false);
jpAdd.add(jsp1);
jpAdd.add(jsp2);
jpAdd.add(pProductList);
jpAdd.add(pTransList);
jpAdd.add(jbAdd);
jpAdd.add(jbClear);
pTransList.setEditable(false);
pProductList.setEditable(false);
jbAdd.addActionListener(this);
jbClear.addActionListener(this);
jpAdd.setVisible(false);
}
public JPanel getAddProduct(){
return jpAdd;
}
@Override
public void actionPerformed(ActionEvent e) {
if(jbClear == e.getSource()){
for(int i = 0; i < jtfPRec.length; i++){
jtfPRec[i].setText("");
}
}
if(jbAdd == e.getSource()){
int pId = Integer.parseInt(jtfPRec[0].getText());
String pName = jtfPRec[1].getText();
String pBrand = jtfPRec[2].getText();
int pQuantity = Integer.parseInt(jtfPRec[3].getText());

for(int i = 0; i < pRec.length; i++){
if(pRec[i] == null){
pRec[i] = new ProductInfo(1,"N","B",1);
pRec[i].setpID(pId);
pRec[i].setpName(pName);
pRec[i].setpBrand(pBrand);
pRec[i].setpQuantity(pQuantity);
break;
}
}
for(int i = 0; i < jtfPRec.length; i++){
jtfPRec[i].setText("");
}
}
}
}
This is a C++ forum. Though some people might know Java I think you have better chances here:
http://www.dreamincode.net/forums/forum/32-java/
Please use code tags, it's hard to read it if you just plaster it without any indentation, be it C++ or Java code.
Topic archived. No new replies allowed.