简体   繁体   English

使JTable可滚动

[英]Make JTable scrollable

I'm trying to create a JTable with 2 columns, one must show the name of the product, the second one, the price. 我正在尝试创建一个有2列的JTable,一个必须显示产品的名称,第二个,价格。 The problem is that the JTable is very small, so i need a scroll, but i can't create it. 问题是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

将它包装在JScrollPane中怎么样?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM