gpt4 book ai didi

java - SWT_AWT 桥 - 组件尺寸

转载 作者:行者123 更新时间:2023-12-01 12:51:57 25 4
gpt4 key购买 nike

我开始尝试使用 SWT-AWT 桥,但我无法为位于 Composite 内的 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();
}
}

结果如下所示:

enter image description here

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

enter image description here

最佳答案

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

shell.setLayout(new FillLayout());

关于java - SWT_AWT 桥 - 组件尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24162855/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com