0

我们可以在 Java 中将 JTable 添加到 JLayeredPane 吗?

4

1 回答 1

2

很简单,使用 JInternalFrame。

使用适当的数据创建表。(前任。)

public static void main(String args[]) {

    JFrame f = new JFrame("JDesktopPane Sample");

    JTable jt = new JTable();

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container content = f.getContentPane();

    JLayeredPane desktop = new JDesktopPane();

    Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3"},
        { "Row2-Column1", "Row2-Column2", "Row2-Column3"} };

    Object columnNames[] = { "Column One", "Column Two", "Column Three"};

    JTable table = new JTable(rowData, columnNames);

    desktop.setOpaque(false);
    desktop.add(createLayer2(table),JLayeredPane.POPUP_LAYER);
    content.add(desktop, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}



public static JInternalFrame createLayer2(JTable n) {

    return new SelfInternalFrame2(n);

}


static class SelfInternalFrame2 extends JInternalFrame {

    public SelfInternalFrame2(JTable n) {

        getContentPane().add(n, BorderLayout.CENTER);

        setBounds(50, 50, 100, 100);

        setResizable(true);

        setClosable(true);

        setMaximizable(true);

        setIconifiable(true);

        setVisible(true);

    }

}
于 2010-04-13T07:05:01.413 回答