[英]JDialog lazy style code generation in Eclipse using WindowBuilder
Is there a way to create JDialogs with Eclipse WindowBuilder and have the automatically generated code in lazy style? 有没有一种方法可以使用Eclipse WindowBuilder创建JDialogs并以自动样式生成自动生成的代码? When I select Lazy in Preferences > WindowBuilder > Swing > Code generation, in JFrames I get lazy style code for all components.
当我在“首选项”>“ WindowBuilder”>“ Swing”>“代码生成”中选择“惰性”时,在JFrames中,我得到了所有组件的惰性样式代码。 However, when I create a JDialog, the code is not lazy - it rather looks like this (note the parts for OK and Cancel buttons):
但是,当我创建JDialog时,代码并不是很懒惰-它看起来像这样(注意OK和Cancel按钮的部分):
public class FactsDialog extends JDialog {
private final JPanel contentPanel = new JPanel();
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
FactsDialog dialog = new FactsDialog();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the dialog.
*/
public FactsDialog() {
setBounds(100, 100, 450, 300);
getContentPane().setLayout(new BorderLayout());
contentPanel.setLayout(new FlowLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
}
}
当您通过WindowBuider开始创建JDialog时,请取消选中创建向导中的“使用OK和Cancel按钮生成JDialog”(文件>新建>其他>窗口生成器> JDialog)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.