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 Newsgroups: comp.lang.java.programmer Subject: Re: Java DatePicker popup calendar Date: Tue, 26 May 2015 17:55:24 +0100 Lines: 142 Message-ID: References: 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: Xref: csiph.com comp.lang.java.programmer:31743 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 */ 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") // 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(); }// 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 */ // /* * 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); } // /* * 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 }