[英]Making a java custom control accessible in Eclipse WindowsBuilder?
這讓我發瘋。 請幫忙。
在Java中,我創建了一個自定義用戶控件。 它是一個JPanel,包含一個標簽,一個文本字段和一個按鈕。 我正在使用Eclipse來完成所有這些工作。 我還使用WindowBuilder將GUI元素拖放到我的自定義控件上。
我希望其他應用程序可以從WindowBuilder訪問此控件。
如何在創建的類別中將此自定義控件添加到Windows Builder?
在.Net中,我將告訴“設計”視圖引用我創建的用戶控件的已編譯DLL。 我認為WindowBuilder / Java也是一樣。
如果有幫助,這是我控制的代碼。
package net.UserControl;
import javax.swing.*;
/* several java.swing imports here */
public class UserControl extends JPanel
{
private JTextField txtfTextField;
private JLabel lblTestLabel;
public UserControl(String greeting)
{
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
lblTestLabel = new JLabel("This textbox will greet you.");
lblTestLabel.setBounds(113, 12, 192, 15);
lblTestLabel.setHorizontalAlignment(SwingConstants.LEFT);
this.add(lblTestLabel);
txtfTextField = new JTextField();
txtfTextField.setBounds(66, 37, 303, 81);
txtfTextField.setHorizontalAlignment(SwingConstants.LEFT);
this.add(txtfTextField);
txtfTextField.setColumns(10);
JButton btnOkButton = new JButton("OK");
btnOkButton.setBounds(184, 130, 54, 25);
this.add(btnOkButton);
btnOkButton.addActionListener(new OkButtonClickManager());
txtfTextField.setText(greeting);
this.setPreferredSize(new Dimension(400, 250));
JScrollPane scrollPane = new JScrollPane(this,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
scrollPane.setPreferredSize(new Dimension(300, 200));
scrollPane.setVisible(true);
}
private static class OkButtonClickManager implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}//end ClickManager
}//end userControl
我覺得我缺少一些簡單的東西。 任何幫助表示贊賞。 謝謝。
請閱讀這篇文章,它將為您提供幫助。 http://help.eclipse.org/juno/topic/org.eclipse.wb.doc.user/html/NewComponentsTutorial.pdf
在我們的項目中,有許多自定義SWT組件,它們在custom_pallet.xml中共享,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<commands>
<addCategory
id="bbs.rcpkit.layout.components"
name="BBS RCPKit Layouts"
description="layout components"
visible="true"
open="true"/>
<addFactory
id="bbs.rcpkit.layout.components.palette"
name="Equal Width Grid"
description="createGrid():"
visible="true"
class="jp.co.bbs.bizwork.eclipse.swt.widgets.WidgetFactory"
signature="createGrid()"
static="true"
category="bbs.rcpkit.layout.components"/>
</command>
您可以定義與工廠方法一樣好的構造函數,還可以添加一些注釋以指示WindowBuilder Pro使用初始設置正確解析組件。
http://help.eclipse.org/juno/topic/org.eclipse.wb.doc.user/html/DesignerCustomizationAPI.pdf
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.