SWT_AWT桥 - 组件大小

时间:2014-06-11 12:23:48

标签: java swing swt-awt

我开始使用SWT-AWT桥接器而且我没有设法为我的JPanel获得一个不错的尺寸,它位于Composite内部。任何人都可以告诉我代码有什么问题吗?

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JPanel;

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.widgets.*;


public class TestSWT_AWT {
    public static void main(String[] args) {            

        final Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setText("SWT and Swing/AWT Example");

        Composite myComp = new Composite(shell, SWT.EMBEDDED  | SWT.NO_BACKGROUND); 

        java.awt.Frame fileTableFrame = SWT_AWT.new_Frame(myComp);
        JPanel panel = new JPanel(new BorderLayout());
        fileTableFrame.add(panel);
        panel.add(new JButton("center"),java.awt.BorderLayout.CENTER);
        panel.add(new JButton("east"),java.awt.BorderLayout.EAST);
        myComp.pack();

        shell.open();
        while (!shell.isDisposed()) {
          if (!display.readAndDispatch())
            display.sleep();
        }
        display.dispose();
    }
}

结果如下:

enter image description here

相反,我希望看到这样的东西(仅摆动)

enter image description here

1 个答案:

答案 0 :(得分:1)

我错过了一行简单的代码:

shell.setLayout(new FillLayout());