【问题标题】:Add pannel to current class in java在java中将面板添加到当前类
【发布时间】:2015-09-01 09:32:21
【问题描述】:

我创建了一个类public class SalesFilterPanel extends Panel。在本课程中,我创建了三个面板 - private Panel createCustomerPanel()、private Panel createDatePanel()、private Panel createAmountPanel()。我想将这 3 个面板添加到 SalesFilterPanel 类。 我的代码是:

public class SalesFilterPanel extends Panel {

private AppCodeFieldPanel customerField;
JLabel customerNameLabel = new JLabel();
private String custid = null;

private JLabel prodNameLabel;
private AppCodeFieldPanel productField;
private String pid = null;

private AppFormattedTextField amountField;
private AppDateTextFieldPanel dateFromField;
private AppDateTextFieldPanel dateToField;

public SalesFilterPanel() {
    super();
    init();
}

private void init() {
    this.setBorder( BorderFactory.createTitledBorder( "Search Criteria" ) );
    createCustomerPanel();
    createDatePanel();
    createAmountPanel();
    this.add( getComponentPopupMenu() );

}
//here are those 3 method's implementation
}

这里如何在SalesFilterPanel中添加这3个面板

【问题讨论】:

    标签: java swing panel


    【解决方案1】:

    你只是 add() Panel 到另一个 Panel。

    假设您的面板创建方法返回 Panel 对象,它只是:-

     this.add(createCustomerPanel());
    

    如果您希望它们采用特定布局,那就是whole other question。

    【讨论】:

    • 我想将 SalesFilterPanel 类的实例创建到另一个“SalesListPanel”类中,并希望将该实例添加到“SalesListPanel”的上面板
    • @VilasGalave 然后在 SalesListPanel 中执行例如Panel upperPanel = new Panel();、upperPanel.add(new SalesFilterPanel());、frame.add(upperPanel, BorderLayout.NORTH);。
    • 太棒了……太完美了。如果我的问题很好,请投票。
    猜你喜欢
    • 2012-08-08
    • 2011-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多