SwingX JXDatePicker getUI failing

eslastamika

New Member
I'm trying to replace a current old date picker with a newer version, that uses the SwingX JXDatePicker. Standalone (in eclipse and executing the runnable jar), this runs great, does everything I want and looks fine. However whenever I try to plug it into my application things start to go wrong.My date picker constructor (the rest is methods to update the date, implement time etc):\[code\]public class DatePickerProto extends JXDatePicker { private static final long serialVersionUID = 1L; private static JSpinner hours; private static JSpinner minutes; public DatePickerProto() { super(); getMonthView().setSelectionModel(new SingleDaySelectionModel()); // Set initial date (current date and time) setDate(new Date()); // Set the output format of the date and time setFormats(new SimpleDateFormat("yyyy-MM-dd HH.mm.ss")); // Replace the JXDatePicker link panel with a new one for entering time setLinkPanel(createTimePanel()); } ...}\[/code\]My main method:\[code\]import javax.swing.JDialog;public class DatePicker { public static void main(String[] args) { final DatePickerProto dateTimeProto = new DatePickerProto(); JDialog dialog = new JDialog(); // Add the date/time picker to the dialog dialog.getContentPane().add(dateTimeProto); dialog.pack(); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); }}\[/code\]So using this main method all works fine standalone, but all it's really doing is just providing a dialog for the picker to be displayed.At the minute all I am trying to do is add the component to a grid of existing components. When adding it to my application the code looks something like this:\[code\]xGrid.addCell(dateProto);\[/code\]XGrid.java:\[code\]public class XGrid extends JComponent { ... public void addCell(JComponent component) { addCell(component, 1, 0); } public void addCell(JComponent component, int gridwidth, int cellpad) { x++; add(component, x, y, gridwidth, 1, columnWeights[x], verticalHungry ? 1.0 : 0.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, createCellInsets(cellpad, x, y), columnWidths[x]); } ...}\[/code\]However doing this throws a NullPointerException:\[code\]UIDefaults.getUI() failed: no ComponentUI class for: javax.swing.JFormattedTextField[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=,caretColor=,disabledTextColor=,editable=true,margin=,selectedTextColor=,selectionColor=,columns=0,columnWidth=0,command=,horizontalAlignment=CENTER]java.lang.Error at javax.swing.UIDefaults.getUIError(UIDefaults.java:712) at javax.swing.MultiUIDefaults.getUIError(MultiUIDefaults.java:133) at javax.swing.UIDefaults.getUI(UIDefaults.java:742) at javax.swing.UIManager.getUI(UIManager.java:989) at javax.swing.text.JTextComponent.updateUI(JTextComponent.java:332) at javax.swing.text.JTextComponent.<init>(JTextComponent.java:306) at javax.swing.JTextField.<init>(JTextField.java:212) at javax.swing.JTextField.<init>(JTextField.java:153) at javax.swing.JFormattedTextField.<init>(JFormattedTextField.java:260) at javax.swing.JSpinner$DefaultEditor.<init>(JSpinner.java:616) at javax.swing.JSpinner$NumberEditor.<init>(JSpinner.java:1194) at javax.swing.JSpinner$NumberEditor.<init>(JSpinner.java:1170) at javax.swing.JSpinner$NumberEditor.<init>(JSpinner.java:1145) at javax.swing.JSpinner.createEditor(JSpinner.java:226) at javax.swing.JSpinner.<init>(JSpinner.java:132) at com.prototype.datepicker.DatePickerProto.createTimePanel(DatePickerProto.java:54) at com.prototype.datepicker.DatePickerProto.<init>(DatePickerProto.java:37) ... Exception occurred: class java.lang.NullPointerException.\[/code\]From what I have found looking into this I think it may be look-and-feel related. Any help that anyone has on this would be greatly appreciated. I'll be happy to provide any further information or anything I have left. Thanks.
 
Back
Top