Сделать JTable прокручиваемым - PullRequest
3 голосов
/ 11 ноября 2011

Я пытаюсь создать JTable с двумя столбцами, один должен показывать название продукта, второй - цену.Проблема в том, что JTable очень маленький, поэтому мне нужен свиток, но я не могу его создать.

enter image description here

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

1 Ответ

9 голосов
/ 11 ноября 2011

Как насчет упаковки в JScrollPane ?

...