Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSpinner format problem

Status
Not open for further replies.

rvy2k

Programmer
Jun 29, 2001
39
0
0
US
Hi guys,

I am trying to create a JSpinner with the following format HH:MM but it is not working. The spinner keeps displaying both the date and the time. Can somebody tell me what's wrong with my code? I would really appreciate it ...

////////////////////////////////////////////////////////////////////////

import java.awt.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;

public class Test {

public static void main(String[] args) {

Frame f = new Frame();
f.setLayout(new BorderLayout());

f.add(new TimeSpinner(), BorderLayout.WEST);
f.add(new TimeSpinner(), BorderLayout.EAST);
f.setVisible(true);
f.pack();
}
}

class TimeSpinner extends JSpinner {

public TimeSpinner() {

super();

// spinner date model
SpinnerDateModel sdm = new SpinnerDateModel();
sdm.setCalendarField(Calendar.MINUTE);
this.setModel(sdm);

try {
this.commitEdit();
} catch (Exception e) {
e.printStackTrace();
}

JSpinner.DateEditor de = (JSpinner.DateEditor)this.getEditor();
de.getFormat().applyPattern("hh:mm a");
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top