Hi all,
I have this weird problem with Jspinners when I try to run this code. When I run it, the second spinner shows the date (while the first one only shows the time) and they are both larger than they are supposed to be (try resizing after it shows up)
Any help would be greatly appreciated.
// CODE STARTS HERE ////////////////////////////////
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class Test {
public static void main(String args[]) {
TimeSpinner spin1 = new TimeSpinner();
TimeSpinner spin2 = new TimeSpinner();
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(spin1);
frame.getContentPane().add(spin2);
frame.setSize(300,300);
frame.show();
}
}
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"
;
}
public void setFixedSize(int width, int height) {
Dimension fixedDimension = new Dimension(width, height);
this.setMinimumSize(fixedDimension);
this.setMaximumSize(fixedDimension);
this.setPreferredSize(fixedDimension);
}
}
I have this weird problem with Jspinners when I try to run this code. When I run it, the second spinner shows the date (while the first one only shows the time) and they are both larger than they are supposed to be (try resizing after it shows up)
Any help would be greatly appreciated.
// CODE STARTS HERE ////////////////////////////////
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class Test {
public static void main(String args[]) {
TimeSpinner spin1 = new TimeSpinner();
TimeSpinner spin2 = new TimeSpinner();
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(spin1);
frame.getContentPane().add(spin2);
frame.setSize(300,300);
frame.show();
}
}
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"
}
public void setFixedSize(int width, int height) {
Dimension fixedDimension = new Dimension(width, height);
this.setMinimumSize(fixedDimension);
this.setMaximumSize(fixedDimension);
this.setPreferredSize(fixedDimension);
}
}