我开始使用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();
}
}
结果如下:
相反,我希望看到这样的东西(仅摆动)
答案 0 :(得分:1)
我错过了一行简单的代码:
shell.setLayout(new FillLayout());