import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import javax.swing.border.*;
import com.borland.jbcl.layout.*;
import javax.swing.*;
import com.borland.dbswing.*;
import java.util.Vector;
import java.util.Date;
import java.text.SimpleDateFormat;
import com.mainet.ali.mts.inv.draw.ejb.session.*;import com.mainet.qd.basic.factory.EJBHomeFactory;import java.sql.Timestamp;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: </p>
 * @author unascribed
 * @version 1.0
 */public class AddTableFrame extends JFrame {  JInternalFrame jif=new JInternalFrame("AliMTS-添加領料單",true,true,true);  private JPanel HeadPanel = new JPanel();
 // private JScrollPane BodyPane = new JScrollPane();
  private JPanel BodyPanel = new JPanel();  private JPanel ButtonPanel = new JPanel();
  private TitledBorder titledBorder1;
  private PaneLayout paneLayout1 = new PaneLayout();
  private TitledBorder titledBorder2;
  private JLabel jLabel1 = new JLabel();
  private JTextField jTextFieldShtdate = new JTextField();
  private JLabel jLabel2 = new JLabel();
  private JTextField jTextFieldShtno = new JTextField();
  private JLabel jLabel3 = new JLabel();
  private JTextField jTextFieldSysdate = new JTextField();
  private JLabel jLabel4 = new JLabel();
  private JLabel jLabel5 = new JLabel();
  private JLabel jLabel6 = new JLabel();
  private JLabel jLabel7 = new JLabel();
  private JLabel jLabel8 = new JLabel();
  private JLabel jLabel9 = new JLabel();
  private JTextField jTextFieldUsrcfmdate = new JTextField();
  private JTextField jTextFieldExseq = new JTextField();
  private JTextField jTextFieldInvcfmdate = new JTextField();
  private JTextField jTextFieldStatus = new JTextField();
  private JLabel jLabel10 = new JLabel();
  private JLabel jLabel11 = new JLabel();
  private JLabel jLabel12 = new JLabel();
  private JLabel jLabel13 = new JLabel();
  private XYLayout xYLayout1 = new XYLayout();
  private JTextField jTextFieldRmk = new JTextField();
  private Border border1;
  private TitledBorder titledBorder3;
  private GridBagLayout gridBagLayout1 = new GridBagLayout();

解决方案 »

  1.   

    Vector columnName = new Vector();
      Vector detalRows = new Vector();  JTable detalTab = new JTable();
      private JButton NextButton = new JButton();
      private JButton jButtonDelete = new JButton();
      private JComboBox jComboBoxDeptno = new JComboBox();
      private JComboBox jComboBoxExpdeptno = new JComboBox();
      private JComboBox jComboBoxUserid = new JComboBox();
      private JComboBox jComboBoxLocaid = new JComboBox();
      private JComboBox jComboBoxExid = new JComboBox();
      private TitledBorder titledBorder4;
      private TitledBorder titledBorder5;
      private JButton AddButton = new JButton();
      private JButton UndoButton = new JButton();
      private JButton ExitButton1 = new JButton();
      private Date now = new Date();
      private Timestamp time = new Timestamp(now.getTime());  public AddTableFrame() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      public JInternalFrame createFrame(){
         jif.setSize(790,548);
         jif.setResizable(false);
         jif.setClosable(true);     jif.setVisible(true);
         jif.setBackground(new Color(212, 208, 200));
         jif.setLocation(1,0);
         Border  border;
         border = BorderFactory.createLineBorder(Color.black);    jif.setBorder(border) ;    try {
          jif.setSelected(true);
        }
        catch (PropertyVetoException ex) {
        }
        jif.show();
         return jif;
      }
    private void jbInit() throws Exception {
      SimpleDateFormat formater = new SimpleDateFormat("yy 年 MM 月 dd 日 ");
       SimpleDateFormat timeformater = new SimpleDateFormat("yy - MM - dd HH:mm:ss ");
      String strDate = formater.format(now) ;
      String strTime = timeformater.format(now) ;
       Vector detalRow = new Vector();
        String[] items={"料號","型號","批號","領料數量","刻號註記","備註"};
        for(int i = 0;i<6;i++){
          columnName.add(i,items[i]);      detalRow.add(i,"");    }    titledBorder4 = new TitledBorder("");
        titledBorder5 = new TitledBorder("");
        NextButton.setBorder(BorderFactory.createLineBorder(Color.black));
        NextButton.setMaximumSize(new Dimension(66, 21));
        NextButton.setMinimumSize(new Dimension(66, 21));
        NextButton.setMnemonic('0');
        NextButton.setText("添加新紀錄");
        NextButton.addMouseListener(new java.awt.event.MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            NextButton_mouseClicked(e);
          }
        });
      

  2.   

    jButtonDelete.setBorder(BorderFactory.createLineBorder(Color.black));
        jButtonDelete.setMaximumSize(new Dimension(78, 21));
        jButtonDelete.setMinimumSize(new Dimension(78, 21));
        jButtonDelete.setText("刪除最後紀錄");
        jButtonDelete.addMouseListener(new java.awt.event.MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            jButtonDelete_mouseClicked(e);
          }
        });
        jTextFieldShtdate.setBackground(SystemColor.inactiveCaptionText);
        jTextFieldShtdate.setEditable(false);
        jTextFieldShtdate.setText(strDate);
        jTextFieldStatus.setBackground(SystemColor.inactiveCaptionText);
        jTextFieldStatus.setEditable(false);
        jTextFieldStatus.setText("01: 立單");
        jTextFieldInvcfmdate.setBackground(SystemColor.inactiveCaptionText);
        jTextFieldInvcfmdate.setEditable(false);
        jTextFieldInvcfmdate.setText("0");
        jComboBoxDeptno.setBorder(BorderFactory.createLineBorder(Color.black));
        jComboBoxDeptno.setMaximumSize(new Dimension(122, 20));
        jComboBoxDeptno.setMinimumSize(new Dimension(122, 20));
        jComboBoxDeptno.setPreferredSize(new Dimension(122, 20));    jComboBoxDeptno.insertItemAt("jg",0);
         jComboBoxDeptno.insertItemAt("xs",1);    jComboBoxExpdeptno.setBorder(BorderFactory.createLineBorder(Color.black));
        jComboBoxExpdeptno.setMaximumSize(new Dimension(32767, 20));
        jComboBoxExpdeptno.setMinimumSize(new Dimension(150, 20));
        jComboBoxExpdeptno.setPreferredSize(new Dimension(150, 20));
        jComboBoxExpdeptno.insertItemAt("js",0);
         jComboBoxExpdeptno.insertItemAt("xs",1);    jTextFieldUsrcfmdate.setBackground(SystemColor.inactiveCaptionText);
        jTextFieldUsrcfmdate.setEditable(false);
        jTextFieldUsrcfmdate.setText("0");
        jComboBoxUserid.setBorder(BorderFactory.createLineBorder(Color.black));
        jComboBoxUserid.setMaximumSize(new Dimension(32767, 20));
        jComboBoxUserid.setMinimumSize(new Dimension(122, 20));
        jComboBoxUserid.setPreferredSize(new Dimension(120, 20));
         jComboBoxUserid.insertItemAt("zez",0);
         jComboBoxUserid.insertItemAt("gll",1);
        jComboBoxLocaid.setBorder(BorderFactory.createLineBorder(Color.black));
        jComboBoxLocaid.setMaximumSize(new Dimension(32767, 20));
        jComboBoxLocaid.setMinimumSize(new Dimension(150, 20));
        jComboBoxLocaid.setPreferredSize(new Dimension(150, 20));
        jComboBoxLocaid.setEditable(true);
         jComboBoxLocaid.insertItemAt("c1",0);
         jComboBoxLocaid.insertItemAt("c2",1);
        jComboBoxExid.setBorder(BorderFactory.createLineBorder(Color.black));
        jComboBoxExid.setPreferredSize(new Dimension(122, 20));
        jComboBoxExid.insertItemAt("ca",0);
         jComboBoxExid.insertItemAt("cb",1);
        jTextFieldShtno.setBackground(SystemColor.inactiveCaptionText);
        jTextFieldShtno.setEditable(false);
        jTextFieldShtno.setText("test1112");
        jTextFieldExseq.setBackground(SystemColor.inactiveCaptionText);
        jTextFieldExseq.setEditable(false);
        jTextFieldExseq.setText("2");
        jTextFieldSysdate.setBackground(SystemColor.inactiveCaptionText);
        jTextFieldSysdate.setText(strTime) ;
        jTextFieldSysdate.setEditable(false);
        AddButton.setToolTipText("確認添加領料單");
        AddButton.setText("確認添加");
        AddButton.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            AddButton_actionPerformed(e);
          }
        });
        UndoButton.setText("清空還原");
        UndoButton.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            UndoButton_actionPerformed(e);
          }
        });
        ExitButton1.setText("退  出");
        ExitButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ExitButton1_actionPerformed(e);
          }
        });
        detalRows.add(0,detalRow);    detalTab=new JTable(detalRows,columnName);
      

  3.   

    titledBorder1 = new TitledBorder("");
        titledBorder2 = new TitledBorder("");
        border1 = BorderFactory.createLineBorder(SystemColor.controlText,2);
        titledBorder3 = new TitledBorder("");
        jif.getContentPane().setLayout(paneLayout1);
        HeadPanel.setBorder(titledBorder1);
        HeadPanel.setLayout(xYLayout1);
        BodyPanel.setBorder(titledBorder2);
        BodyPanel.setLayout(gridBagLayout1);
        ButtonPanel.setBorder(BorderFactory.createLineBorder(Color.black));
        titledBorder1.setTitle("領料單");
        titledBorder2.setTitle("領料明細");
        jLabel1.setText("立單日期:");
        jTextFieldShtdate.setBorder(BorderFactory.createLineBorder(Color.black));
        jLabel2.setText("單號號碼:");
        jTextFieldShtno.setBorder(BorderFactory.createLineBorder(Color.black));
        jLabel3.setText("系統日期:");
        jTextFieldSysdate.setBorder(BorderFactory.createLineBorder(Color.black));
        jLabel4.setText("出庫區分:");
        jLabel5.setText("出庫倉別:");
        jLabel6.setText("立單人:");
        jLabel7.setText("領料部門:");
        jLabel8.setText("費用歸屬部門:");
        jLabel9.setText("確認日期:");
        jTextFieldUsrcfmdate.setBorder(BorderFactory.createLineBorder(Color.black));
        jTextFieldExseq.setBorder(BorderFactory.createLineBorder(Color.black));
        jTextFieldInvcfmdate.setBorder(BorderFactory.createLineBorder(Color.black));
        jTextFieldStatus.setBorder(BorderFactory.createLineBorder(Color.black));
        jLabel10.setText("倉庫發料序號:");
        jLabel11.setText("發料日期:");
        jLabel12.setText("表單狀態:");
        jLabel13.setText("備註:");
        jTextFieldRmk.setBorder(BorderFactory.createLineBorder(Color.black));    jif.setMaximizable(false);
            detalTab.setRowHeight(22);
            detalTab.setBackground(new Color(181,214,255));
            //detalTab.setPreferredScrollableViewportSize(new Dimension(828,355));        JScrollPane scr=new JScrollPane(detalTab);    scr.setAutoscrolls(true);
        scr.setBorder(BorderFactory.createLineBorder(Color.black));
        scr.setToolTipText("");    BodyPanel.add(scr,   new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0
                ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 10, 0, 10), 0, 0));
        BodyPanel.add(NextButton,    new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
                ,GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(2, 50, 1, 10), 0, 0));
        BodyPanel.add(jButtonDelete, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
                ,GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(2, 0, 1, 80), 0, 0));    HeadPanel.add(jTextFieldStatus,    new XYConstraints(606, 121, 126, -1));
        HeadPanel.add(jLabel13, new XYConstraints(16, 158, -1, -1));
        HeadPanel.add(jLabel10, new XYConstraints(16, 122, -1, -1));
        HeadPanel.add(jLabel4, new XYConstraints(16, 47, -1, -1));
        HeadPanel.add(jTextFieldShtdate,  new XYConstraints(90, 5, 126, -1));
        HeadPanel.add(jTextFieldExseq,  new XYConstraints(105, 119, 126, -1));
        HeadPanel.add(jTextFieldRmk, new XYConstraints(90, 157, 645, -1));
        HeadPanel.add(jLabel11, new XYConstraints(253, 123, -1, -1));
        HeadPanel.add(jLabel8, new XYConstraints(253, 81, -1, -1));
        HeadPanel.add(jLabel5, new XYConstraints(253, 43, -1, -1));
        HeadPanel.add(jLabel2, new XYConstraints(253, 6, -1, -1));
        HeadPanel.add(jTextFieldShtno,  new XYConstraints(347, 2, 165, -1));
        HeadPanel.add(jTextFieldInvcfmdate,   new XYConstraints(347, 120, 165, -1));
        HeadPanel.add(jTextFieldUsrcfmdate,  new XYConstraints(606, 79, 126, -1));
        HeadPanel.add(jTextFieldSysdate,  new XYConstraints(606, 5, 126, -1));
        HeadPanel.add(jLabel3, new XYConstraints(537, 4, -1, -1));
        HeadPanel.add(jLabel6, new XYConstraints(537, 45, -1, -1));
        HeadPanel.add(jLabel9, new XYConstraints(537, 81, -1, -1));
        HeadPanel.add(jLabel12, new XYConstraints(537, 122, -1, -1));
        HeadPanel.add(jLabel1, new XYConstraints(15, 10, -1, -1));
        HeadPanel.add(jLabel7, new XYConstraints(16, 85, -1, -1));
      

  4.   


        jif.getContentPane().add(HeadPanel,   new PaneConstraints("jPanel1", "jPanel1", PaneConstraints.ROOT, 0.5f));
        jif.getContentPane().add(ButtonPanel,   new PaneConstraints("jPanel3", "jPanel1", PaneConstraints.BOTTOM, 0.595978f));
        ButtonPanel.add(AddButton, null);
        ButtonPanel.add(UndoButton, null);
        ButtonPanel.add(ExitButton1, null);
        jif.getContentPane().add(BodyPanel,   new PaneConstraints("jPanel2", "jPanel3", PaneConstraints.TOP, 0.84294873f));
        HeadPanel.add(jComboBoxDeptno,  new XYConstraints(89, 82, 126, -1));
        HeadPanel.add(jComboBoxExpdeptno,    new XYConstraints(347, 80, 165, -1));
        HeadPanel.add(jComboBoxUserid,  new XYConstraints(605, 44, 126, -1));
        HeadPanel.add(jComboBoxLocaid,  new XYConstraints(346, 39, 165, -1));
        HeadPanel.add(jComboBoxExid,   new XYConstraints(89, 46, -1, -1));
      }  void NextButton_mouseClicked(MouseEvent e) {
        Vector detalRow = new Vector();
        for(int i = 0 ; i < 6;i++){      detalRow.add(i,"");    }
        detalRows.add(detalTab.getRowCount(),detalRow) ;
        detalTab.updateUI();  }  void jButtonDelete_mouseClicked(MouseEvent e) {
        if(detalTab.getRowCount() >0){
        detalRows.remove(detalTab.getRowCount()-1) ;
        detalTab.updateUI();}
      }  void UndoButton_actionPerformed(ActionEvent e) {
        jTextFieldRmk.setText("") ;
        jComboBoxDeptno.setSelectedIndex(-1);
        jComboBoxExpdeptno.setSelectedIndex(-1);
        jComboBoxUserid .setSelectedIndex(-1);
        jComboBoxLocaid.setSelectedIndex(-1);
        jComboBoxExid.setSelectedIndex(-1);
        detalRows.removeAllElements() ;
        Vector detalRow = new Vector();
        for(int i=0;i<6;i++){       detalRow.add(i,"");
        }
        detalRows.add(0,detalRow) ;
        detalTab.updateUI();
      }  void ExitButton1_actionPerformed(ActionEvent e) {
        jif.dispose() ;
      }  void AddButton_actionPerformed(ActionEvent e) {
       Vector bellhead = new Vector();
        Vector belldetal = new Vector();
        String shtno = jTextFieldShtno.getText() ;
        Timestamp shtdate = time;
        String exid = (String)jComboBoxExid.getSelectedItem() ;
        String locaid = (String)jComboBoxLocaid.getSelectedItem();
        String deptno = (String)jComboBoxDeptno.getSelectedItem();
        String expdeptno = (String)jComboBoxExpdeptno.getSelectedItem() ;
        String rmk = jTextFieldRmk.getText() ;
        String exseq = jTextFieldExseq.getText() ;
        String userid = (String)jComboBoxUserid.getSelectedItem() ;
        Timestamp sysdate = time;
        Timestamp usrcfmdate = null;
        Timestamp expcfmdate = null;
        Timestamp pcfmdate = null;
        Timestamp invcfmdate = null;
        String status = jTextFieldStatus.getText() ;
        bellhead.add(0,shtno     );
        bellhead.add(1,shtdate   );
        bellhead.add(2,exid      );
        bellhead.add(3,locaid    );
        bellhead.add(4,deptno    );
        bellhead.add(5,expdeptno );
        bellhead.add(6,rmk       );
        bellhead.add(7,exseq     );
        bellhead.add(8,userid    );
        bellhead.add(9,sysdate   );
        bellhead.add(10,usrcfmdate);
        bellhead.add(11,expcfmdate);
        bellhead.add(12,pcfmdate  );
        bellhead.add(13,invcfmdate);
        bellhead.add(14,status);
     try {
        for(int i=0;i<detalRows.size() ;i++){
          Vector tempvv = (Vector)detalRows.elementAt(i) ;
          tempvv.setElementAt(new Integer((String)tempvv.elementAt(3)),3);
        }
       belldetal = detalRows;      MtsSessionHome home = (MtsSessionHome)EJBHomeFactory.lookUpHome(MtsSessionHome.class);
          MtsSession session = home.create() ;
        session.insertPickingBill(bellhead,belldetal) ;    MessageDialog dlg = new MessageDialog(this,"ok");
        dlg.show();
        UndoButton_actionPerformed( e);
        }catch (NamingException ex) {
        //  ex.printStackTrace() ;
          MessageDialog dlg = new MessageDialog(this,"error");
          dlg.show();
          UndoButton_actionPerformed( e);
        }catch (Exception ex) {
        //  ex.printStackTrace() ;
          MessageDialog dlg = new MessageDialog(this,"error");
          dlg.show();
          UndoButton_actionPerformed( e);
        }  }}
      

  5.   

    我自己写了一个小项目,你可看看,里面的所有界面布局都是用GridBagLayout的,因代码大长,共3500多行,无法在这里放下,若想要看,请留联系方式
      

  6.   

    to: callzjy
       能否将你的小项目代码供我学习,本人学生,大三,急需学习经验
       [email protected]
       拜谢!
      

  7.   

    看看这个是否符合你的要求:import java.awt.*;
    import javax.swing.*;/**
     * Title:
     * Description:
     * Copyright:    Copyright (c) 2003
     * Company:
     * @author
     * @version 1.0
     */public class Frame5 extends JFrame {
      GridBagLayout gridBagLayout1 = new GridBagLayout();
      JLabel lblMailto = new JLabel();
      JTextField txtMailto = new JTextField();
      JLabel lblTitle = new JLabel();
      JTextField txtTitle = new JTextField();
      JLabel lblCC = new JLabel();
      JTextField txtCC = new JTextField();
      JTextArea txtBody = new JTextArea();
      JLabel lblAttachment = new JLabel();
      JComboBox cmbAttachment = new JComboBox();
      JButton btnBrowse = new JButton();  public Frame5() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      public static void main(String[] args) {
        Frame5 frame5 = new Frame5();
      }
      private void jbInit() throws Exception {
        lblMailto.setToolTipText("");
        lblMailto.setText("收件人:");
        this.getContentPane().setLayout(gridBagLayout1);
        txtMailto.setToolTipText("收件人信息...");
        txtMailto.setColumns(20);
        lblTitle.setText("标题:");
        txtTitle.setToolTipText("标题信息...");
        txtTitle.setColumns(20);
        lblCC.setText("转发:");
        txtCC.setToolTipText("转发信息...");
        txtCC.setColumns(20);
        txtBody.setToolTipText("信件内容...");
        txtBody.setRows(10);
        lblAttachment.setText("附件:");
        btnBrowse.setPreferredSize(new Dimension(67, 22));
        btnBrowse.setText("...");
        cmbAttachment.setPreferredSize(new Dimension(150, 22));
        this.getContentPane().add(lblMailto,  new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        this.getContentPane().add(txtMailto,   new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        this.getContentPane().add(lblTitle,   new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        this.getContentPane().add(txtTitle,   new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        this.getContentPane().add(lblCC,   new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        this.getContentPane().add(txtCC,   new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        this.getContentPane().add(txtBody,    new GridBagConstraints(0, 3, 3, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        this.getContentPane().add(lblAttachment,   new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        this.getContentPane().add(cmbAttachment,   new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        this.getContentPane().add(btnBrowse,  new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0
                ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
        pack();
        show();
      }
    }
      

  8.   

    一看都知道是JBuilder老手,呵呵。