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!

weird jspinner problem

Status
Not open for further replies.

rvy2k

Programmer
Jun 29, 2001
39
0
0
US
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);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top