2013-05-28 20 views
0

我在JPanelGridLayout內有兩個JTable對象。我把它們放在JOptionPane中,我將它們顯示爲OK_CANCEL彈出窗口。我還在兩張桌子上放了JScrollPaneJOptionPane中的JPanel內部的JTable將不會根據需要調整大小

但是,JOptionPane的大小是巨大的。我曾嘗試用不同的設置表,滾動窗格和JPanel的大小:

table.setSize(int w, int h) 
jpanel.setSize(int w, int h) 
jscrollpane.setSize(int w, int h) 

但沒有那些將導致較小的JOptionPane(或表)。

這就是它的樣子,我用1366 * 768作爲分辨率。上面提到的都不會做出任何區別

This is how it looks

private void showEditItemSuppliersDialog() 
    { 
    String newItemSupplierTables [] = { "#", "Name", "" }; 
     JPanel panel = new JPanel(new GridLayout(0, 2, 5, 5)); 

     /* table 1 */ 
     allItemsEditItemSuppliersTableModel = new DefaultTableModel(null, newItemSupplierTables); 

     allItemsEditItemSuppliersTable = new JTable(allItemsEditItemSuppliersTableModel); 
     allItemsEditItemSuppliersTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 

     JScrollPane allItemsEditItemSuppliersTableScrollPane = new JScrollPane(); 
     allItemsEditItemSuppliersTableScrollPane.setViewportView(allItemsEditItemSuppliersTable); 
     /* table 1 end */ 

     /* table 2 */ 
     allItemsEditItemSuppliersAllTableModel = new DefaultTableModel(null, newItemSupplierTables); 

     allItemsEditItemSuppliersAllTable = new JTable(allItemsEditItemSuppliersAllTableModel); 
     allItemsEditItemSuppliersAllTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 

     JScrollPane allItemsEditItemSuppliersAllTableScrollPane = new JScrollPane(); 
     allItemsEditItemSuppliersAllTableScrollPane.setViewportView(allItemsEditItemSuppliersAllTable); 
     /* table 2 end*/ 

     panel.add(allItemsEditItemSuppliersTableScrollPane); 
     panel.add(allItemsEditItemSuppliersAllTableScrollPane); 

     int option = JOptionPane.showConfirmDialog(null, panel, "Edit", JOptionPane.OK_CANCEL_OPTION); 

     if (option == JOptionPane.YES_OPTION) 
     { 
      System.out.println("Pressed OK"); 
     } 
    } 

回答

相關問題