Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31743

Re: Java DatePicker popup calendar

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Nigel Wade <nmw@ion.le.ac.uk>
Newsgroups comp.lang.java.programmer
Subject Re: Java DatePicker popup calendar
Date Tue, 26 May 2015 17:55:24 +0100
Lines 142
Message-ID <csjmrsF7gp3U1@mid.individual.net> (permalink)
References <ff683251-9cb0-4451-970f-91b13dc3280d@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net QDXleAVp8f/WUz0sJYB1yQR0CKnqRRXUc8Eh95WILN/tL3GdqK
Cancel-Lock sha1:FCPv9YdvP6U4/lb++e49ppeuBWo=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5
In-Reply-To <ff683251-9cb0-4451-970f-91b13dc3280d@googlegroups.com>
Xref csiph.com comp.lang.java.programmer:31743

Show key headers only | View raw


On 23/05/15 17:57, Daniel Negri wrote:
> I have downloaded Microba DatePicker and JDatePicker. Can I make it always stay popped up from the start (without actioning the button, and even after choosing the date to remain popped up). What I actually want is getting just the calendar itself, without the other elements.
>

To get just the calendar use com.michaelbaranov.microba.calendar.CalendarPane as a normal component, and add it to your GUI.

This is a very basic JDialogForm application created by NetBeans/matisse where a CalendarPane is created and added to a 
JPanel. If you run it with the correct classpath you should get today's calendar displayed.

For example:
javac -cp ~/Java/lib/microba-0.4.4.3.jar TestCalendar.java
java -cp ~/Java/lib/microba-0.4.4.3.jar:. TestCalendar

select a date and press the "Show date" button. The selected date should be written to System.out.

The code:

import com.michaelbaranov.microba.calendar.CalendarPane;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/*
  * To change this license header, choose License Headers in Project Properties.
  * To change this template file, choose Tools | Templates
  * and open the template in the editor.
  */

/**
  *
  * @author Nigel Wade <nmw@le.ac.uk>
  */
public class TestCalendar extends javax.swing.JDialog {
   CalendarPane calendar = new CalendarPane(new Date());

   /**
    * Creates new form TestCalender
    */
   public TestCalendar(java.awt.Frame parent, boolean modal) {
     super(parent, modal);
     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.
    */
   @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">
   private void initComponents() {

     jPanel1 = new javax.swing.JPanel();
     jPanel2 = new javax.swing.JPanel();
     jButton1 = new javax.swing.JButton();

     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

     jPanel1.setLayout(new java.awt.BorderLayout());

     jButton1.setText("Show date");
     jButton1.addActionListener(new java.awt.event.ActionListener() {
       public void actionPerformed(java.awt.event.ActionEvent evt) {
         jButton1ActionPerformed(evt);
       }
     });
     jPanel2.add(jButton1);

     jPanel1.add(jPanel2, java.awt.BorderLayout.SOUTH);

     jPanel1.add(calendar);
     getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

     pack();
   }// </editor-fold>

   private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
     Date date = calendar.getDate();
     DateFormat df = new SimpleDateFormat("EEE, MMM d, yyyy");
     System.out.println(df.format(date));
   }

   /**
    * @param args the command line arguments
    */
   public static void main(String args[]) {
     /*
      * Set the Nimbus look and feel
      */
         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
         /*
      * If Nimbus (introduced in Java SE 6) is not available, stay with the
      * default look and feel. For details see
      * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
      */
     try {
       for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
         if ("Nimbus".equals(info.getName())) {
           javax.swing.UIManager.setLookAndFeel(info.getClassName());
           break;
         }
       }
     }
     catch (ClassNotFoundException ex) {
       java.util.logging.Logger.getLogger(TestCalendar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
     }
     catch (InstantiationException ex) {
       java.util.logging.Logger.getLogger(TestCalendar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
     }
     catch (IllegalAccessException ex) {
       java.util.logging.Logger.getLogger(TestCalendar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
     }
     catch (javax.swing.UnsupportedLookAndFeelException ex) {
       java.util.logging.Logger.getLogger(TestCalendar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
     }
         //</editor-fold>

     /*
      * Create and display the dialog
      */
     java.awt.EventQueue.invokeLater(new Runnable() {
       public void run() {
         TestCalendar dialog = new TestCalendar(new javax.swing.JFrame(), true);
         dialog.addWindowListener(new java.awt.event.WindowAdapter() {
           @Override
           public void windowClosing(java.awt.event.WindowEvent e) {
             System.exit(0);
           }
         });
         dialog.setVisible(true);
       }
     });
   }

   // Variables declaration - do not modify
   private javax.swing.JButton jButton1;
   private javax.swing.JPanel jPanel1;
   private javax.swing.JPanel jPanel2;
   // End of variables declaration
}

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Java DatePicker popup calendar Daniel Negri <dangelo.negri@gmail.com> - 2015-05-23 09:57 -0700
  Re: Java DatePicker popup calendar e.d.programmer@gmail.com - 2015-05-26 08:32 -0700
  Re: Java DatePicker popup calendar Nigel Wade <nmw@ion.le.ac.uk> - 2015-05-26 17:55 +0100

csiph-web