簡體   English   中英

Java jTable在jScrollPane內部不可見

[英]Java jTable is not visible inside jScrollPane

您好,我在JScrollPane中顯示JTable時遇到問題。

這是我的代碼:

table = new JTable();
    table.setBounds(16, 203, 362, 16);
    //getContentPane().add(table);
    table.setShowHorizontalLines(true);
    table.setShowVerticalLines(true);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setModel(new DefaultTableModel(
        new Object[][] {
            {"2", "DN Korina", "200"},
        },
        new String[] {
            "QTY", "Item Code", "Amount"
        }
    ));
    table.getColumnModel().getColumn(0).setPreferredWidth(105);
    table.getColumnModel().getColumn(1).setPreferredWidth(244);
    table.getColumnModel().getColumn(2).setPreferredWidth(220);
    table.setBackground(Color.PINK);
    JTableHeader header = table.getTableHeader();
    header.setBackground(Color.yellow);
    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.setBounds(16, 480, 359, -240);
    getContentPane().add(scrollPane);

我正在使用WindowBuilder Pro,但在設計視圖中看不到jScrollPane。 如果刪除了JScrollPane並讓JTable離開,則JTable是可見的。 但是我看不到標題。 我讀過要查看JTable的標頭,必須將JTable放在JScrollPane內。 有什么想法為什么我看不到我的JScrollPane和JTable? 謝謝。

終於,我成功了!

我為JTable和JScrollPane設置了相同的界限。

table = new JTable();
table.setBounds(16, 203, 362, 16);


scrollPane.setBounds(16, 203, 362, 266);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM