2013-11-23 77 views
0

我無法找到將數據插入我的JTable中的JPanel的方法。 任何人都可以幫我弄明白嗎?我做錯了什麼?將數據插入JTable中的JPanel - JAVA

這裏是我的代碼:

JTabbedPane tabProcessamentoSalarial = new JTabbedPane(JTabbedPane.TOP); 
tabbedPane.addTab("Remunera\u00E7\u00F5es", null, tabProcessamentoSalarial, null); 

JPanel pnlAcumulados = new JPanel(); 
tabProcessamentoSalarial.addTab("Acumulados", null, pnlAcumulados, null); 
     pnlAcumulados.setLayout(null); 

     table_1 = new JTable(); 
     table_1.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null)); 
     table_1.setBounds(46, 36, 508, 160); 
     pnlAcumulados.add(table_1); 


     JScrollPane scrollPane = new JScrollPane(); 
     scrollPane.setBounds(46, 36, 508, 160); 
     pnlAcumulados.add(scrollPane); 

     tblAcumulados = new JTable(); 
     tblAcumulados.setBounds(46, 36, 508, 160); 
     tblAcumulados.setModel(new DefaultTableModel() { 
      String[] columnNamesRui = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"}; 

      Object[][] dataRui = { 
       {"Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false)}, 
       {"John", "Doe", "Rowing", new Integer(3), new Boolean(true)}, 
       {"Sue", "Black", "Knitting", new Integer(2), new Boolean(false)}, 
       {"Jane", "White", "Speed reading", new Integer(20), new Boolean(true)}, 
       {"Joe", "Brown", "Pool", new Integer(10), new Boolean(false)} 
      }; 
     } 
     ); 

回答

2

什麼,我做錯了什麼?

爲什麼從Swing教程中更改代碼?教程代碼工作正常,所以如果你不明白你在做什麼,你爲什麼要修改它?

  1. 您不應該使用空佈局。
  2. 爲什麼不使用表作爲構造函數來創建scrollpane?

再次使用Swing教程How to Use Tables中的示例重新開始。