我开始尝试使用SWT-AWT桥,但我没有设法为我的JPanel找到一个合适的大小,它位于一个复合文件中。谁能给我一个提示,代码出了什么问题?
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();
}
}结果如下所示:

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

发布于 2014-06-11 20:38:51
我遗漏了一行简单的代码:
shell.setLayout(new FillLayout());https://stackoverflow.com/questions/24162855
复制相似问题