我在JTable
内有两个JPanel
个对象GridLayout
。我将它们放在JOptionPane
中,然后将其显示为OK_CANCEL
弹出窗口。我还在两个表上放了一个JScrollPane
。
然而,JOptionPane
的大小是巨大的。我尝试使用:
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");
}
}