I am trying to create an application which generates a scrollbar when to much is on the screen. Most examples i've seen use a table object as a parameter for ScrollPane, but I'm not sure what to use as a parameter for this application. How can I do this? (My code is at the bottom) Thanks!
//**************** TimeSheet.java *************************
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TimeSheet extends Frame implements ActionListener
{
// static TextField tf1,tfArray1[i+1],tfArray1[i+2],tfArray1[i+3];
static Cell object1;
// static Label theLabel[i],theLabel[i+1];
// static TextField tf1_2,tfArray1[i+1]_2,tfArray1[i+2]_2,tfArray1[i+3]_2;
// static Label theLabel[i]_2,theLabel[i+1]_2;
static int i = 0;
static Cell [] cellArray = new Cell[10];
static TextField [] tfArray1 = new TextField[100];
static TextField [] tfArray2 = new TextField[100];
static TextField [] tfArray3 = new TextField[100];
static TextField [] tfArray4 = new TextField[100];
static Label [] theLabel = new Label[100];
public TimeSheet()
{
//Cell [] object1 = new Cell[5];
/*
for (i=0;i
<9;i++){
cellArray[i] = new Cell();
}*/
cellArray[0] = new Cell();
cellArray[1] = new Cell();
cellArray[2] = new Cell();
cellArray[3] = new Cell();
cellArray[4] = new Cell();
cellArray[5] = new Cell();
cellArray[6] = new Cell();
cellArray[7] = new Cell();
cellArray[8] = new Cell();
tfArray1[0] = new TextField("20");
tfArray1[1] = new TextField("21");
tfArray2[1] = new TextField();
tfArray3[0] = new TextField();
tfArray4[0] = new TextField();
}
public static void main(String args[])
{
int T = 0;
int l = 0;
TimeSheet t = new TimeSheet();
for (int a = 0;a
<4;a++){
tfArray1[T] = new TextField("20");
tfArray1[T+1] = new TextField("15");
tfArray1[T+2] = new TextField("30");
tfArray1[T+3] = new TextField("10");
cellArray[i].setTextField1(tfArray1[T]);
cellArray[i].setTextField2(tfArray1[T+1]);
cellArray[i].setTextField3(tfArray1[T+2]);
cellArray[i].setTextField4(tfArray1[T+3]);
tfArray1[T].addActionListener(t);
tfArray1[T+1].addActionListener(t);
tfArray1[T+2].addActionListener(t);
tfArray1[T+3].addActionListener(t);
t.add(cellArray[i].getTextField1());
t.add(cellArray[i].getTextField2());
theLabel[l] = cellArray[i].getLabel(tfArray1[T],tfArray1[T+1]);
t.add(theLabel[l]);
t.add(cellArray[i].getTextField3());
t.add(cellArray[i].getTextField4());
theLabel[l+1] = cellArray[i].getLabel(tfArray1[T+2],tfArray1[T+3]);
t.add(theLabel[l+1]);
i++;
T=T+4;
l=l+2;
tfArray1[T] = new TextField("20");
tfArray1[T+1] = new TextField("15");
tfArray1[T+2] = new TextField("30");
tfArray1[T+3] = new TextField("10");
cellArray[i].setTextField1(tfArray1[T]);
cellArray[i].setTextField2(tfArray1[T+1]);
cellArray[i].setTextField3(tfArray1[T+2]);
cellArray[i].setTextField4(tfArray1[T+3]);
//cellArray[i].setcellArray(i);
tfArray1[T].addActionListener(t);
tfArray1[T+1].addActionListener(t);
tfArray1[T+2].addActionListener(t);
tfArray1[T+3].addActionListener(t);
t.add(cellArray[i].getTextField1());
t.add(cellArray[i].getTextField2());
theLabel[l] = cellArray[i].getLabel(tfArray1[T],tfArray1[T+1]);
t.add(theLabel[l]);
t.add(cellArray[i].getTextField3());
t.add(cellArray[i].getTextField4());
theLabel[l+1] = cellArray[i].getLabel(tfArray1[T+2],tfArray1[T+3]);
t.add(theLabel[l+1]);
i++;
T=T+4;
l=l+2;
}
// ScrollPane sp1 = new ScrollPane();
//sp1.add(t);
t.setLayout(new FlowLayout());
t.setSize(5000,1000);
t.show(true);
/*
Frame fr = new Frame("ScrollPane test");
ScrollPane pane = new ScrollPane();
pane.setSize(200, 200);
pane.add(new FlowLayout());
//TimeSheet.getContentPane().add();
fr.add(pane);
fr.pack();
fr.setVisible(true);
Adjustable vadj = pane.getVAdjustable();
Adjustable hadj = pane.getHAdjustable();
vadj.setUnitIncrement(5);
hadj.setUnitIncrement(5);
*/
}
public void SpreadSheet(){
}
public void actionPerformed(ActionEvent e)
{
int k =0;
int c=0;
int t = 0;
int l = 0;
System.out.println(e.getActionCommand() + " " + e.getActionCommand());
System.out.println(e.getModifiers());
System.out.println(e.paramString());
//int i = cellArray[i].getcellArray();
/*
theLabel[i].setText(cellArray[i].getLabel(tfArray1[i],tfArray1[i+1]).getText());
theLabel[i+1].setText(cellArray[i].getLabel(tfArray1[i+2],tfArray1[i+3]).getText());
*/
for (int a = 0;a
<4;a++){
theLabel[l].setText(cellArray[c].getLabel(tfArray1[t], tfArray1[t+1]).getText());
theLabel[l+1].setText(cellArray[c].getLabel(tfArray1[t+2], tfArray1[t+3]).getText());
l=l+2;
c++;
t=t+4;
theLabel[l].setText(cellArray[c].getLabel(tfArray1[t], tfArray1[t+1]).getText());
theLabel[l+1].setText(cellArray[c].getLabel(tfArray1[t+2], tfArray1[t+3]).getText());
l=l+2;
c++;
t=t+4;
}
/*
theLabel[i]_2.setText(cellArray[i].getLabel(tfArray1[i],tfArray1[i+1]_2).getText());
theLabel[i+1]_2.setText(cellArray[i].getLabel(tfArray1[i+2]_2,tfArray1[i+3]_2).getText());
*/
}
}
//************** End of TimeSheet.java *********************
<<Less