0

我开始使用 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();
    }
}

结果如下所示:

在此处输入图像描述

相反,我想看到这样的东西(仅限摇摆)

在此处输入图像描述

4

1 回答 1

1

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

shell.setLayout(new FillLayout());
于 2014-06-11T12:38:51.300 回答