Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 摆动式全尺寸JPanel_Java_Swing_Jpanel - Fatal编程技术网

Java 摆动式全尺寸JPanel

Java 摆动式全尺寸JPanel,java,swing,jpanel,Java,Swing,Jpanel,如何达到外板的全宽 private JPanel createLabelPanel() { final JToolTip tt = new JToolTip(); //tt.setSize(new Dimension(100,200)); final CompoundBorder cb = new CompoundBorder(tt.getBorder(), BorderFactory.createEmptyBorder(2, 2, 2,

如何达到外板的全宽

    private JPanel createLabelPanel() {

        final JToolTip tt = new JToolTip();
        //tt.setSize(new Dimension(100,200));
        final CompoundBorder cb = new CompoundBorder(tt.getBorder(), BorderFactory.createEmptyBorder(2, 2, 2, 2));
        final JPanel innerPanel = new JPanel();
        innerPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        innerPanel.setBorder(cb);
        innerPanel.setBackground(tt.getBackground());
        innerPanel.add(displayLabel);
        innerPanel.setBorder(BorderFactory.createLineBorder(Color.GREEN));

        final JScrollPane tooltipscrool = new JScrollPane(innerPanel);
        //tooltipscrool.setMinimumSize(new Dimension(200,100));
        tooltipscrool.setPreferredSize(new Dimension(100,120));
        tooltipscrool.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        final JPanel outerPanel = new JPanel();
        outerPanel.add(tooltipscrool);
        outerPanel.setBorder(BorderFactory.createLineBorder(Color.GREEN));
        //outerPanel.set
        return outerPanel;
    }
让我:


我的目标是拥有全宽的innerPanel(绿色)。

JPanel
默认使用
FlowLayout
,它倾向于使用每个组件的首选大小来定义其大小

改用
边框布局
,例如

final JPanel outerPanel = new JPanel(new BorderLayout());
请查看以了解更多详细信息


您还应该尽可能避免使用
setPreferredSize
,查看更多详细信息

我不知道JPanel默认使用FlowLayout,谢谢!我不能点击了:/n不用担心,如果您对答案满意,您应该很快就能点击绿色的点击;)@Phi先生进来不是问题;)