Link to home
Start Free TrialLog in
Avatar of MarkLoveExEx
MarkLoveExEx

asked on

Java DateChooser?

I need a graphical way to show a Calendar, pick a date off that Calendar, and use that date.  Any suggestions?

I've tried to use Jcalendar-1.4.jar, but I can't get the Calendar to actually show up on the JPanel/JFrame.

Here is my complete code, if someone can help me figure out what I'm doing wrong...
import javax.swing.SwingUtilities;

public class StartHere {
	
	public static TopLevelFrame myTopLevelFrame;
	

	public static void main(String[] args) throws Exception {
		
		
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				try {
					myTopLevelFrame = new TopLevelFrame();
					myTopLevelFrame.setVisible(true);
					new Thread(new Runnable() {

						@Override
						public void run() {
							try {
							} catch (NullPointerException e) {
								e.printStackTrace();
							} catch (Exception f) {
								f.printStackTrace();
							}
						}
					}).start();
				} catch (Exception e) {
					e.printStackTrace();
					System.out.println("Something when wrong");
				}
			}
		});
	}
}

Open in new window


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;

public class TopLevelFrame extends JFrame implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	static JTabbedPane tabbedPane = new JTabbedPane();
	JComponent myJPanel_Setup = new JPanel_Setup();

//	JComponent myJPanel_ApplePi = new JPanel_ApplePi();

	@Override
	public void actionPerformed(ActionEvent arg0) {
	}
	
	public TopLevelFrame() throws Exception {
		super("SCHEDULE");
		setSize(1280, 1000);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		add(tabbedPane);
		
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				try {

					myJPanel_Setup.setVisible(true);


//					myJPanel_ApplePi.setVisible(true);
				} catch (Exception e) {
				}
			}
		});

		try {
			tabbedPane.addTab("Setup", myJPanel_Setup);
			
//			tabbedPane.addTab("APPLEPI", myJPanel_ApplePi);

		} catch (IllegalArgumentException ill) {
			ill.printStackTrace();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Open in new window


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.toedter.calendar.JDateChooser;


public class JPanel_DateChooser extends JPanel implements ActionListener, ListSelectionListener {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public JPanel_DateChooser() throws Exception {
    	super();
        JPanel panel = new JPanel();

        JDateChooser myDateChooser = new JDateChooser();
        myDateChooser.getCalendar();
        myDateChooser.setVisible(true);
        panel.add(myDateChooser);

    }

	@Override
	public void valueChanged(ListSelectionEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}
}

Open in new window


import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class JPanel_Setup extends JPanel implements ActionListener, ListSelectionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JTextField JTextField_Sunday = new JTextField(5);
	JTextField JTextField_Monday = new JTextField(5);
	JComponent myJPanel_DateChooser = new JPanel_DateChooser();
	
	@Override
	public void valueChanged(ListSelectionEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	public JPanel_Setup() throws Exception {
		super();
		
		
		JTextField_Sunday.setFont(new Font(Font.MONOSPACED,Font.BOLD,13));
		JTextField_Monday.setFont(new Font(Font.MONOSPACED,Font.BOLD,13));
		myJPanel_DateChooser.setVisible(true);
		
add(myJPanel_DateChooser);
		add(JTextField_Sunday);
		add(JTextField_Monday);
		
	}

}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MarkLoveExEx
MarkLoveExEx

ASKER

omg.  what a stupid mistake I made.  thank you very much for finding my error.  :)
Try JDatePicker