0
我在JPanel
和GridLayout
內有兩個JTable
對象。我把它們放在JOptionPane
中,我將它們顯示爲OK_CANCEL
彈出窗口。我還在兩張桌子上放了JScrollPane
。JOptionPane中的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作爲分辨率。上面提到的都不會做出任何區別
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");
}
}
謝謝,只要我能接受答案,我會盡我所需。 – Nikola