你说的绝对不肯能(我这里有很多例子),改变LookAndFeel只是改变它的画风,并没有改变它处理事件的那部分东西。如果你说的是无法自动获得焦点,那么在你处理JComboBox的事件的最后加上textArea.requestFocus();不就好了吗?

解决方案 »

  1.   

    感谢shine333(shine) ,但是这种textArea.requestFocus()方法我已经试过了,没有用。
    用鼠标点都点不进去。
      

  2.   

    同意 bluesmile979(笑着) (
      

  3.   

    上面两位大侠,在那个类里面就没有出现过setEnable以下是代码,我是在JBuilder7里面做的,用了那个XYLayout,是不是和这个Layout有关啊???import java.awt.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    import java.awt.event.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: </p>
     * @author unascribed
     * @version 1.0
     */public class AddNewRecordDialog extends JDialog
    {
      private JPanel panel1 = new JPanel();
      private XYLayout xYLayout1 = new XYLayout();
      private JLabel jLabel1 = new JLabel();
      private JLabel jLabel2 = new JLabel();
      private JComboBox jComboBox1 = new JComboBox();
      private JScrollPane jScrollPane1 = new JScrollPane();
      private JTextArea jTextArea1 = new JTextArea();
      private JButton jButton1 = new JButton();
      private JButton jButton2 = new JButton();  ///
      /**
       * submitOrCancel的值: 1表示submit,0表示cancel
       * */
      public static int submitOrCancel=0;  /**
       * selected的值: 0表示学习记录,1表示事务记录
      */
      public static int selected=0;  /**
       *记录内容
       */
      public static String content="";
      ///  public AddNewRecordDialog(Frame frame, String title, boolean modal)
      {
        super(frame, title, modal);
        try
        {
          jbInit();
          pack();
        }
        catch(Exception ex)
        {
          ex.printStackTrace();
        }
      }  public AddNewRecordDialog()
      {
        this(null, "", false);
      }
      private void jbInit() throws Exception
      {
        panel1.setLayout(xYLayout1);
        this.setTitle("添加一条记录");
        jLabel1.setText("请选择记录类型:");
        jLabel2.setText("请在下面输入记录内容:");
        jButton1.setText("提交");
        jButton1.addActionListener(new java.awt.event.ActionListener()
        {
          public void actionPerformed(ActionEvent e)
          {
            jButton1_actionPerformed(e);
          }
        });
        jButton2.setText("取消");
        jButton2.addActionListener(new java.awt.event.ActionListener()
        {
          public void actionPerformed(ActionEvent e)
          {
            jButton2_actionPerformed(e);
          }
        });
        getContentPane().add(panel1);    ///
        jComboBox1.addItem("学习记录");
        jComboBox1.addItem("事务记录");
        ///    panel1.add(jComboBox1,  new XYConstraints(191, 60, 125, -1));
        panel1.add(jLabel1,  new XYConstraints(54, 62, -1, -1));
        panel1.add(jLabel2, new XYConstraints(54, 110, -1, -1));
        panel1.add(jScrollPane1,  new XYConstraints(54, 140, 284, 103));
        panel1.add(jButton1,   new XYConstraints(54, 270, -1, -1));
        panel1.add(jButton2,         new XYConstraints(191, 270, -1, -1));
        jScrollPane1.getViewport().add(jTextArea1, null);
        this.setSize(400,350);    ///
        jButton1.registerKeyboardAction(new ActionListener()
          {
            public void actionPerformed(ActionEvent e)
            {
              jButton1_actionPerformed(e);
            }
          },KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),JComponent.WHEN_IN_FOCUSED_WINDOW);    jButton2.registerKeyboardAction(new ActionListener()
          {
            public void actionPerformed(ActionEvent e)
            {
              jButton2_actionPerformed(e);
            }
          },KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),JComponent.WHEN_FOCUSED);    ///
      }  void jButton1_actionPerformed(ActionEvent e)
      {
        if(jTextArea1.getText().equals(""))
        {
          JOptionPane.showMessageDialog(null,"您没有输入记录内容,请检查!","error",JOptionPane.ERROR_MESSAGE);
        }
        else
        {
          this.submitOrCancel=1;
          this.selected=jComboBox1.getSelectedIndex();
          this.content=jTextArea1.getText();      this.dispose();
        }
      }  void jButton2_actionPerformed(ActionEvent e)
      {
        this.submitOrCancel=0;    this.dispose();
      }
    }