使JTable具有滚动条功能

3
我试图创建一个拥有两列的 JTable,其中一列必须显示产品名称,第二列必须显示价格。问题在于 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

如果Tim Bender的建议对您有所帮助,请不要忘记“接受”他的答案。 - Hovercraft Full Of Eels
在StackOverflow上,问题的提问者通常会“接受”一个答案,而不是编辑标题为“(已解决)”。这将标记问题已被回答(答案计数以金色显示)。如果您解决了自己的问题,则可以回答自己的问题并接受该答案。 - Tim Bender
1个回答

9

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接