我正在做一个JFrame
从我的数据库中动态添加的标签。在这种情况下,有时会显示 3 个数据,有时会显示 5 个数据。
该程序确实显示了内容,但它只显示了适合屏幕的数据。这意味着当我向下滚动时,什么都看不到。有谁知道我哪里错了?
public class Trip extends JFrame implements ActionListener {
ConnectionDB database = new ConnectionDB();
public Trip() throws SQLException
{
super("Trip");
Container c = getContentPane();
c.setLayout(new BorderLayout());
Definition a =new Definition();
int NoOfAS = a.travelTime(User.UserID);
Panel p = new Panel(new GridLayout(1,2));
Panel p1 = new Panel(new GridLayout(NoOfAS,1));
Label title = new Label("Itinerary");
title.setFont(new Font("Serif", Font.BOLD, 48));
c.add(title,"North");
JScrollPane scroll = new JScrollPane(p);
c.add(scroll,"Center");
for(int i=0;i<NoOfAS;i++)
{
String ASNAME = database.retrieveASNameItinerary(User.UserID,"AS_Name",i+1);
Label no = new Label("No:"+ (i+1) +" "+ASNAME);
no.setFont(new Font("Times New Noman",Font.BOLD,20));
Label descp = new Label(database.retrieveAS_Des(ASNAME,"AS_Description"));
Label SugTime = new Label("Suggested Time:"+database.retrieveAS_Des(ASNAME,"AS_Time"));
Label bus = new Label("Bus:"+database.retrieveAS_Des(ASNAME,"AS_Transport"));
Label fee = new Label("Fees:"+database.retrieveAS_Des(ASNAME,"AS_Price"));
Label line = new Label("---------------------------------------------------");
line.setForeground (Color.red);
Panel p2 = new Panel(new GridLayout(6,1));
p2.add(no);
p2.add(descp);
p2.add(SugTime);
p2.add(bus);
p2.add(fee);
p2.add(line);
p1.add(p2);
p.add(p1);
}
// setSize(900,1700);
pack();
show();
}
public static void main(String args[]) throws SQLException
{
StdPlan app = new StdPlan( );
app.addWindowListener(new WindowAdapter( ){});
}
@Override
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
}