Java 如何在JScrollPane的左上角添加组件?

Java 如何在JScrollPane的左上角添加组件?,java,swing,awt,jscrollpane,Java,Swing,Awt,Jscrollpane,我已经创建了一个带有RowHeaderView、一个ColumnHeaderView和一个ViewPortView的JScrollPane。我添加了不同颜色的JPanel并注意到,左上角有一个cornor,在左上角,您不能只添加组件。我想问,如何才能在那里添加组件 这里有一张图片。我指的是绿色区域: 这是我的代码: public class Example { public static void main(String[] args) { JFrame frame

我已经创建了一个带有
RowHeaderView
、一个
ColumnHeaderView
和一个
ViewPortView的
JScrollPane
。我添加了不同颜色的JPanel并注意到,左上角有一个cornor,在左上角,您不能只添加
组件。我想问,如何才能在那里添加
组件

这里有一张图片。我指的是绿色区域:

这是我的代码:

public class Example {

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setSize(1000, 800);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);

        JPanel panel0 = new JPanel();
        panel0.setBackground(Color.yellow);
        JPanel panel1 = new JPanel();
        panel1.setBackground(Color.red);
        panel1.setPreferredSize(new Dimension(30, 200));
        JPanel panel2 = new JPanel();
        panel2.setBackground(Color.blue);
        panel2.setPreferredSize(new Dimension(200, 30));
        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setViewportView(panel0);
        scrollPane.setRowHeaderView(panel1);
        scrollPane.setColumnHeaderView(panel2);
        scrollPane.setBackground(Color.green);

        frame.add(scrollPane);
        frame.setVisible(true);
    }

}


这很容易。使用setCorner方法

scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, new JButton());

谢谢你,谢谢你。我在hole time中搜索另一个名称中包含“view”的方法。