3

2 つの列を持つ JTable を作成しようとしています。1 つは製品の名前、もう 1 つは価格を表示する必要があります。問題は、JTable が非常に小さいため、スクロールが必要なのですが、作成できません。

ここに画像の説明を入力

DefaultTableModel model = new DefaultTableModel();
    JTable productos = new JTable(model);


    model.addColumn("Product");//name of the first columns
    model.addColumn("Price");//name of the second columns
    BTW: the table doesn't show the name of the column, but creates the 2 columns


    for (i=0; i<null_copy4; i++)//null_copy4 is a integer that shows me how many stacks are used in the array
    {
        model.insertRow(model.getRowCount(), new Object[]{product_copy3[i],price_copy3[i]});
    }
           //product_copy3 and price_copy3 are arrays. String[] and integer[].
    products.setBounds(5,50,200,200); //define the dimensions of the JTable
    this.add(productos);//add it to the window
4

1 に答える 1

9

JScrollPaneでラップするのはどうですか?

于 2011-11-10T22:01:08.147 に答える