2011-11-10 36 views
3

我試圖創建一個2列的JTable,必須顯示產品的名稱,第二個價格。問題是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 
+0

如果Tim Bender的建議幫助了你,不要忘記「接受」他的答案。 –

+0

在StackOverflow上,不是編輯標題來說「(已解決)」,而是通常「接受」答案。這將標記問題爲答案(答案數以黃金顯示)。如果你解決了自己的問題,那麼你可以回答自己的問題並接受答案。 –

回答