{ //对OutlayPanel和IncomePanel分别定义 incomePanel.setLayout(gridbag); GridBagConstraints cc = new GridBagConstraints(); cc.gridx = 0 ; cc.gridy = 0; // c.gridwidth = GridBagConstraints.RELATIVE; // c.gridheight = GridBagConstraints.RELATIVE; cc.fill = GridBagConstraints.BOTH; cc.weightx = 1.0; cc.weighty = 1.0; JLabel label1 = new JLabel("金额 (元):"); label1.setFont(font); incomePanel.add(label1, cc); //**** cc.gridx = 0 ; cc.gridy = 1; JLabel label2 = new JLabel("收入分类:"); label2.setFont(font); incomePanel.add(label2, cc); //**** cc.gridx = 0 ; cc.gridy = 2; JLabel label3 = new JLabel("时间(选择):"); label3.setFont(font); incomePanel.add(label3, cc); //***** cc.gridx = 1 ; cc.gridy = 0; text3.setFont(inputFont); incomePanel.add(text3, cc); //**** cc.gridx = 1 ; cc.gridy = 1; Object labels[] = {"薪资薪酬", "利润奖励", "意外惊喜"}; //today面板上的下拉选择框 comboBox2 = new JComboBox(labels); comboBox2.setFont(inputFont); comboBox2.setBackground(new Color(0, 128, 255)); //下拉选择框的颜色 incomePanel.add(comboBox2, cc); //**** cc.gridx = 1; //时间 cc.gridy = 2; text4.setPreferredSize(new Dimension(100, 10)); //选择时间的输入框,暂时不支持DatePicker text4.setFont(inputFont); text4.setText(CalendarUtils.rightnow()); incomePanel.add(text4, cc); //********* cc.gridx = 2; cc.gridy = 0; cc.gridheight = 3; incomePanel.add(scrollPane2, cc); //***** cc.gridx = 3; cc.gridy = 0; cc.gridheight = 3; JButton jb = new JButton("保存收入"); jb.setCursor(btcurson); jb.setFont(btnFont); jb.setPreferredSize(new Dimension(40, 30)); jb.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //TabButtonAction.save_content(param1, param2); if (isNeeded(text3.getText())) { System.out.println(text4.getText() + " | " + text3.getText() + " " + jt.getText() + " " + (String)comboBox2.getSelectedItem()); } else JOptionPane.showMessageDialog(null, "请确认您的输入,金额不能识别", "来自系统的提示:", JOptionPane.WARNING_MESSAGE); } }); incomePanel.add(jb, cc); } } } ////输入验证类 public Boolean isNeeded(String input){ return input.matches("^[1-9][0-9]*?.??[0-9]??[0-9]??"); //规范 } public static void updateContent(String str) { // ja.setText(ja.getText() + "\r\n" + str); } public static void clearContent() { // ja.setText(""); } public JPanel getCenterPane() { return centerPane; } public MyToolBar getToolBar() { return toolbar; } }