swing测试类Test中单击jtextfield选择日期无反应是什么原因,谢谢大家了!

DateChooser类本身无问题,

/*

  • Test.java *
  • Created on DATE, TIME */

package com.fxy.test;

import java.awt.event.ActionEvent;

/**
*

  • @author USER
    */
    public class Test extends javax.swing.JFrame {

    DateChooser dateChooser = DateChooser.getInstance("yyyy-MM-dd");

    /** Creates new form Test */
    public Test() {
    initComponents();
    }

    /** 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.
      */
      //GEN-BEGIN:initComponents
      //
      private void initComponents() {

      jPanel1 = new javax.swing.JPanel();
      jTextField1 = new javax.swing.JTextField("单击选择日期");

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

      jTextField1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jTextField1ActionPerformed(evt);
      }
      });

      javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
      jPanel1);
      jPanel1.setLayout(jPanel1Layout);
      jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(
      javax.swing.GroupLayout.Alignment.LEADING).addGroup(
      jPanel1Layout
      .createSequentialGroup()
      .addGap(79, 79, 79)
      .addComponent(jTextField1,
      javax.swing.GroupLayout.PREFERRED_SIZE, 95,
      javax.swing.GroupLayout.PREFERRED_SIZE)
      .addContainerGap(29, Short.MAX_VALUE)));
      jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(
      javax.swing.GroupLayout.Alignment.LEADING).addGroup(
      jPanel1Layout
      .createSequentialGroup()
      .addGap(89, 89, 89)
      .addComponent(jTextField1,
      javax.swing.GroupLayout.PREFERRED_SIZE,
      javax.swing.GroupLayout.DEFAULT_SIZE,
      javax.swing.GroupLayout.PREFERRED_SIZE)
      .addContainerGap(95, Short.MAX_VALUE)));

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
      getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(layout.createParallelGroup(
      javax.swing.GroupLayout.Alignment.LEADING).addGroup(
      layout.createSequentialGroup()
      .addGap(50, 50, 50)
      .addComponent(jPanel1,
      javax.swing.GroupLayout.PREFERRED_SIZE,
      javax.swing.GroupLayout.DEFAULT_SIZE,
      javax.swing.GroupLayout.PREFERRED_SIZE)
      .addContainerGap(147, Short.MAX_VALUE)));
      layout.setVerticalGroup(layout.createParallelGroup(
      javax.swing.GroupLayout.Alignment.LEADING).addGroup(
      layout.createSequentialGroup()
      .addGap(42, 42, 42)
      .addComponent(jPanel1,
      javax.swing.GroupLayout.PREFERRED_SIZE,
      javax.swing.GroupLayout.DEFAULT_SIZE,
      javax.swing.GroupLayout.PREFERRED_SIZE)
      .addContainerGap(48, Short.MAX_VALUE)));

      pack();
      }//
      //GEN-END:initComponents

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
    jtf1ActionPerformed(evt);
    }

    private void jtf1ActionPerformed(ActionEvent evt) {
    dateChooser.register(jTextField1);
    }

    /**

    • @param args the command line arguments
      */
      public static void main(String args[]) {
      java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
      new Test().setVisible(true);

      }
      

      });
      }

    //GEN-BEGIN:variables
    // Variables declaration - do not modify
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

}

2个回答

fxyxl
fxyxl 打开没有解决方案么
3 年多之前 回复

没人知道哪出问题了么?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问