窗体装载窗体
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了窗体装载窗体相关的知识,希望对你有一定的参考价值。
//复写窗体添加按钮,对要复写的窗体的工具栏创建getset方法,即可在承载窗体上获得工具栏对象
1.
public JToolBar getjToolBar1() {
return jToolBar1;
}
public void setjToolBar1(JToolBar jToolBar1) {
this.jToolBar1 = jToolBar1;
}
2.//在构造方法里调用添加按钮方法
public DgEditDeclarant() {
initComponents();
pnDeclarant = new PnDeclarant();
addButton();
this.add(pnDeclarant, java.awt.BorderLayout.CENTER);
}
3.//添加按钮
private void addButton() {
JToolBar tb = pnDeclarant.getjToolBar1();
JBButton btn = new JBButton();
btn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bsw/esp/client/images/35_确定.png"))); // NOI18N
btn.setText("确定");
btn.setAuthorityID("");
btn.setBorderPainted(false);
btn.setFocusable(false);
btn.setHorizontalTextPosition(0);
btn.setIconTextGap(0);
btn.setVerticalTextPosition(3);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectData = (Declarant) pnDeclarant.getTableModel().getCheckedRow();
if (selectData == null) {
JOptionPane.showMessageDialog(rootPane, "请选择数据");
return;
} else {
isOk = true;
dispose();
}
}
});
tb.add(btn);
}
4.//调用承载窗体
DgEditDeclarant dg = new DgEditDeclarant();
dg.setVisible(true);
if (dg.getIsOk()) {
Declarant declarant = dg.getSelectData();
if (declarant != null) {
initDeclarant();
ItemProperty it = new ItemProperty(declarant.getCode(), declarant.getName());
cbbDeclarant.setSelectedItem(it);
}
} else {
initDeclarant();
}
//承载窗体代码
public class DgEditDeclarant extends JDialogBase {
private PnDeclarant pnDeclarant;
private Boolean isOk = false;
private Declarant selectData;
/**
* Creates new form NewJDialog
*/
public DgEditDeclarant() {
initComponents();
pnDeclarant = new PnDeclarant();
addButton();
this.add(pnDeclarant, java.awt.BorderLayout.CENTER);
}
@Override
public void setVisible(boolean b) {
if (b) {
super.setVisible(b); //To change body of generated methods, choose Tools | Templates.
}
}
private void addButton() {
JToolBar tb = pnDeclarant.getjToolBar1();
JBButton btn = new JBButton();
btn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/bsw/esp/client/images/35_确定.png"))); // NOI18N
btn.setText("确定");
btn.setAuthorityID("");
btn.setBorderPainted(false);
btn.setFocusable(false);
btn.setHorizontalTextPosition(0);
btn.setIconTextGap(0);
btn.setVerticalTextPosition(3);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectData = (Declarant) pnDeclarant.getTableModel().getCheckedRow();
if (selectData == null) {
JOptionPane.showMessageDialog(rootPane, "请选择数据");
return;
} else {
isOk = true;
dispose();
}
}
});
tb.add(btn);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setBounds(0, 0, 500, 373);
}// </editor-fold>
public Boolean getIsOk() {
return isOk;
}
public void setIsOk(Boolean isOk) {
this.isOk = isOk;
}
public Declarant getSelectData() {
return selectData;
}
public void setSelectData(Declarant selectData) {
this.selectData = selectData;
}
// Variables declaration - do not modify
// End of variables declaration
}
以上是关于窗体装载窗体的主要内容,如果未能解决你的问题,请参考以下文章