【问题标题】:ContentPane NOT resizing at design time in Eclipse IDEContentPane 不在 Eclipse IDE 中的设计时调整大小
【发布时间】:2013-10-19 11:30:43
【问题描述】:

我正在使用 Eclipse Window Builder 工具包设计全屏桌面应用程序
而且,我在设计中发现了这个奇怪的问题
我正在使用 GroupLayout,我必须在其上放置组件,但正如您在我提供的图像中看到的那样,正在放置的组件之间存在差异。

这里是IDE生成的源码:

package info.visual.gui;

import java.awt.EventQueue;

import javax.swing.JFrame;
import java.awt.Color;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;

public class MDI {

    public JFrame frame;
    /**
     * @wbp.nonvisual location=487,159
     */
    private final JButton button = new JButton("New button");

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    MDI window = new MDI();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public MDI() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.getContentPane().setBackground(new Color(0, 0, 0));

        JButton btnButton = new JButton("button1");
        GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
        groupLayout.setHorizontalGroup(
            groupLayout.createParallelGroup(Alignment.LEADING)
                .addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
                    .addContainerGap(319, Short.MAX_VALUE)
                    .addComponent(btnButton)
                    .addGap(26))
        );
        groupLayout.setVerticalGroup(
            groupLayout.createParallelGroup(Alignment.LEADING)
                .addGroup(groupLayout.createSequentialGroup()
                    .addGap(113)
                    .addComponent(btnButton)
                    .addContainerGap(125, Short.MAX_VALUE))
        );
        frame.getContentPane().setLayout(groupLayout);
        frame.setExtendedState(6);
        frame.setResizable(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

看看这些代码行

/**
     * @wbp.nonvisual location=487,159
     */
    private final JButton button = new JButton("New button");

这是我很好奇的事情,最重要的是这个问题。 任何人都可以澄清我应该怎么做才能让内容窗格扩展到全尺寸,因为框架在设计时...... 谢谢。。

【问题讨论】:

    标签: java eclipse swing


    【解决方案1】:

    我遇到了同样的问题,我通过调整框架而不是 ContentPane 的大小来解决它。
    只需拖放框架(窗口)的右下角,直到您到达框架的中间(例如),ContentPane 现在应该有一个新的大小,您应该可以正确地看到您的组件。

    【讨论】:

      猜你喜欢
      • 2012-06-05
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 2015-07-15
      • 2013-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多