1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
   | package test;
 
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.table.*;
 
public class NestedScrollpanes extends JFrame {
    private static final long serialVersionUID = 1L;
 
    private TableModel getTableModel() {
        return new DefaultTableModel(new Object[] {
                "A", "B", "C", "D", "E", 
                "F", "G", "H", "I", "J", 
                "K", "L", "M", "N", "O"}, 100);
    }
 
    public NestedScrollpanes() {
        super("Test");
        JPanel rootPanel = new JPanel(new BorderLayout());
        JTabbedPane tabbedPane = new JTabbedPane();
        JScrollPane rootScrollPane = new JScrollPane(tabbedPane); // A
        JTable table = new JTable(getTableModel());
        JScrollPane tableScrollPane = new JScrollPane(table); // B
 
        getContentPane().add(rootPanel, BorderLayout.CENTER);
        rootPanel.add(rootScrollPane);
        tabbedPane.addTab("TAB", tableScrollPane);
        setSize(100, 100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }
 
    public static void main(String[] args) {
        new NestedScrollpanes();
    }
} | 
Partager