JSpinner « Component « Java Swing Q&A





1. Custom JSpinner    stackoverflow.com

I have created the following class that extends JSpinner to iterate over dd/mm/yyy values.


public class DateSpinner extends JSpinner{

    Calendar calendar = new GregorianCalendar();

    public DateSpinner(){
 ...

2. Java Swing - Problem in JSpinner    stackoverflow.com

I am developing a Java Desktop Application and designing the GUI with the help of Netbeans Swing GUI builder. I want to use a JSpinner in my app. I have dragged and ...

3. How to set jspinner as non editable?    stackoverflow.com

I am creating time picker using the spinner.In that the text inside the spinner is editable.But i want to set the spinner as non editable.Because is there chance to give invalid ...

4. JSpinner SpinnerDateModel question    stackoverflow.com

I'm trying to create a JSpinner to enable the user to pick a Date. I want there to be a lower date limit and an upper date limit. I also want ...

5. Setting Time Format for jspinner in swings    stackoverflow.com

I am working in a java swing application. In that application i have to take time input from user. I need to make a JSpinner for the time, only in the hh:mm ...

6. JSpinner.DateEditor must include year even though start and end is the same year    stackoverflow.com

I have a JSpinner using a SpinnerDateModel which has a start at Jan 1, 2010 00:00:00.000 the end date is Jan 1, 2010 00:12:34.217. I would like my JSpinner.DateEditor to use ...

7. Formatting initial values with JSpinner    stackoverflow.com

I want to change the default decimal format for a JSpinner, specifying a number of decimal places but leaving other formatting locale specific. But if I do this

@Test public void fails() {
 ...

8. Java lookandfeels that work with SpinnerDateModel    stackoverflow.com

I have a DateSpinner that uses a SpinnerDateModel, and I need the spinner increment to be the day of the month. This is how I initialize it:

new JSpinner(new SpinnerDateModel(new Date(), ...

9. Disabling digit grouping in a JSpinner    stackoverflow.com

I needed a widget to select a TCP/UDP port, so I wrote the following:

public static JSpinner makePortSpinner()
{
    final JSpinner spinner = new JSpinner(
      ...





10. Set text colour of a disabled JSpinner (to make it easier to read)    stackoverflow.com

JSpinner waitHr  = new JSpinner();
waitHr.setEnabled(false);
I have a spinner and I need to prevent the user from editing it temporarily. The problem is, when the spinner is disabled, it's text colour ...

11. Increase the size of the arrows on the JSpinner    stackoverflow.com

How to increase the size of the arrows on the JSpinner.

12. Weird JSpinner behaviour    stackoverflow.com

I encountered the weirdest behaviour of swings JSpinner. The spinner looks like this (the component in the middle is the spinner): enter image description here As you notice, it has no ...

13. JSpinners with shared SpinnerModel    stackoverflow.com

I'm trying to set up multiple JSpinners to edit a single Date value - i.e. one spinner for days, one for months, etc. It seems like I ought to be able to ...

14. Is it possible to change the background of a jspinner using the nimbus laf?    stackoverflow.com

I'm fairly confident that I have done my research before coming to you for help, but it's possible I have overlooked something. I'm writing a java UI using the Nimbus l-a-f. I ...

15. Java: how do I make JSpinner show value with some offset    stackoverflow.com

In my application some values internally have their range from 0. But user should see this range starting from 1. I thought it would be appropriate to move this offseting stuff ...

16. JSpinner without negative values    stackoverflow.com

I'm building a small application in netbeans,i use a JSpinner component to set the quantity of a product,but i want to get only positive values.How can set the spinner to change ...





17. off-topic (pure swing question): why doesn't this JSpinner limit input?    forums.netbeans.org

I have a JSpinner to represent the year: Calendar calendar = Calendar.getInstance(); int currentYear = calendar.get(Calendar.YEAR); SpinnerNumberModel yearModel = new SpinnerNumberModel(currentYear, currentYear - 100, currentYear + 100,1); spinner.setModel(yearModel); JSpinner.NumberEditor editor = ...

18. JSPINNER - ABOUT TIME!    coderanch.com

Hi all Just thought that I would introduce you all to JSpinner, a new feature in J2SDK 1.4. JSpinner provides the arrow interface to increment a value in a textfield. An example of this is in your windows date/time settings, you'll see that you can adjust the year by moving the little arrows to the right of the textbox. I'm surprised ...

19. JSpinner SpinnerDateModel    coderanch.com

20. JSpinner question    coderanch.com

21. JSpinner DateModel : Set a date    coderanch.com

hi, here is how I did it: (the spinner shows only the year: 'yyyy'). g.gridx = 0; g.gridy++; g.gridwidth = 1; g.fill = g.HORIZONTAL; g.anchor = g.NORTHWEST; g.insets = new Insets(12, 12, 5, 5); startPyBox = new JCheckBox("Start At Year"); startPyBox.setSelected(false); advancedSearchPanel.add(startPyBox, g); Date startDate = null; if (minPY != Range.NO_LIMIT) { startDate = new GregorianCalendar(minPY, 1, 1).getTime(); } Date endDate ...

22. JSpinner Problem    coderanch.com

Hi, I'm using JSpinner's to display a time in HH:mm format. the code: SpinnerDateModel sdmNextTimeSpinnerDateModel = new SpinnerDateModel() { public Object getNextValue() { GregorianCalendar cal = new GregorianCalendar(); cal.setTime( getDate() ); cal.add( Calendar.MINUTE, 15 ); return cal.getTime(); } public Object getPreviousValue() { GregorianCalendar cal = new GregorianCalendar(); cal.setTime( getDate() ); cal.add( Calendar.MINUTE, -15 ); return cal.getTime(); } }; sdmNextTimeSpinnerDateModel.setValue( gregcalNext.getTime() ); ...

23. JSpinner question    coderanch.com

hey, I am working on a program that really doesnt do anything. But I was trying to utilize JSpinners using the SpinnerNumberModel. Here's what I am trying to have work. If I have two JSpinners, and I click to change the value on one of them, how can I find out whether it went up or down so I can change ...

24. JSpinners revisited    coderanch.com

I've added JSpinners to my program and they look beautiful. I used JSpinnerNumberModel to display the value and so it shows an int between 0 and 10. My problem of course as there is always a problem when I make a new topic, is reading the number on the JSpinner when it changes. In a previous topic, someone suggested using the ...

25. JSpinner    coderanch.com

26. jspinner background color    coderanch.com

import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.swing.*; public class ChangingColors { static Random seed; public static void main(String[] args) { seed = new Random(); final JSpinner spinner = new JSpinner(); spinner.setPreferredSize(new Dimension(150,25)); JPanel panel = new JPanel(); panel.add(spinner); JButton button = new JButton("change color"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JTextField tf = ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField(); tf.setBackground(getNewColor()); } }); JPanel ...

27. JSpinner with dates    coderanch.com

I'm using a JSPinner that I'm defaulting to today with a max of today like this: spnrMdl = new SpinnerDateModel(new Date(), null, new Date(), Calendar.DAY_OF_MONTH); spnr = new JSpinner(spnrMdl); When I run this it shows the date in MM/DD/YY HH:mm PM format. When I click on the down spinner button, it highlights and decrements the month not the day. If I ...

28. JSpinner text not updating    coderanch.com

29. JSpinner and arrows    coderanch.com

30. JSpinner Size    coderanch.com

Yes. import java.awt.*; import javax.swing.*; public class SpinnerSize { public SpinnerSize() { String[] suits = { "spades", "diamonds", "clubs", "hearts" }; SpinnerListModel suitModel = new SpinnerListModel(suits); JSpinner suitSpinner = new JSpinner(suitModel); // set the preferred size Dimension d = suitSpinner.getPreferredSize(); d.width = 100; suitSpinner.setPreferredSize(d); // modify the JTextField appearance JSpinner.ListEditor editor = new JSpinner.ListEditor(suitSpinner); JTextField tf = editor.getTextField(); tf.setHorizontalAlignment(JTextField.CENTER); tf.setFont(new Font("lucida ...

31. Reading out JSpinner    coderanch.com

32. JSpinner Problem    coderanch.com

33. jspinner question    coderanch.com

34. jspinner minimum value    coderanch.com

35. JSpinner decimal input    coderanch.com

Is it possible to configure a JSpinner so that it will allow me to format a field for input of a value with 3 decimal places. I have tried several ways some of which display 0.000 etc but when I exit the field the value to the right if the decimal point reset back to .000 Some posts imply that a ...

36. JSpinner & SpinnerNumberModel    coderanch.com

38. 2 JSpinners has my head spinning!    coderanch.com

Welcome to the Ranch. You are not using two anonymous classes? I have just had discussions on that point with somebody else on this forum here. There is nothing wrong with having two anonymous inner classes, otherwise you will accumulate if elses and you code becomes difficult to understand. You will notice in the post I quoted that I say you ...

40. Unable to use JSpinner properly.    coderanch.com

Here's the stack trace. Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Attempt to mutate in notification at javax.swing.text.AbstractDocument.writeLock(AbstractDocument.java:1343) at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:662) at javax.swing.text.JTextComponent.setText(JTextComponent.java:1441) at javax.swing.JFormattedTextField$AbstractFormatter.install(JFormattedTextField.java:925) at javax.swing.text.DefaultFormatter.install(DefaultFormatter.java:105) at javax.swing.text.InternationalFormatter.install(InternationalFormatter.java:268) at javax.swing.JFormattedTextField.setFormatter(JFormattedTextField.java:443) at javax.swing.JFormattedTextField.setValue(JFormattedTextField.java:767) at javax.swing.JFormattedTextField.setValue(JFormattedTextField.java:480) at javax.swing.JSpinner$DefaultEditor.stateChanged(JSpinner.java:696) at javax.swing.JSpinner.fireStateChanged(JSpinner.java:426) at javax.swing.JSpinner$ModelListener.stateChanged(JSpinner.java:353) at javax.swing.AbstractSpinnerModel.fireStateChanged(AbstractSpinnerModel.java:102) at javax.swing.SpinnerNumberModel.setValue(SpinnerNumberModel.java:430) at com.core.java_ui.pagesetup.OptionsTab$SpinnerDocumentListener.updateSpinner(OptionsTab.java:294) at com.core.java_ui.pagesetup.OptionsTab$SpinnerDocumentListener.insertUpdate(OptionsTab.java:258) at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:184) at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:754) at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:711) at javax.swing.text.PlainDocument.insertString(PlainDocument.java:114) at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:673) at javax.swing.text.JTextComponent.setText(JTextComponent.java:1441) at javax.swing.JFormattedTextField$AbstractFormatter.install(JFormattedTextField.java:925) at ...

41. Is it possible for a JSpinner to show no default value?    coderanch.com

> show no default value will hiding it do? import javax.swing.*; import java.awt.*; import javax.swing.event.*; class Testing { public void buildGUI() { final JSpinner spinner = new JSpinner(new SpinnerNumberModel(1,0,10,1)); final JTextField spinnerTF = ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField(); final Color spinnerForeground = spinnerTF.getForeground(); final Color spinnerBackground = spinnerTF.getBackground(); spinnerTF.setColumns(5); spinner.addChangeListener(new ChangeListener(){ public void stateChanged(ChangeEvent ce){ if(((Integer)spinner.getValue()).intValue() == 0) { spinnerTF.setForeground(spinnerBackground); } else spinnerTF.setForeground(spinnerForeground); } }); ...

42. JSpinner - How to initialize to the top of list    coderanch.com

OK - I have a list of names, say - Andy, Bill, Christina. These names are loaded into the array used to initialize JSpinner in this order - [0] Andy, [1] Bill, [3} Christina. When the JSpinner appears, "Christina" shows up, requiring the user to go up to find the rest of the names. Intuitively, one would expect the top name, ...

43. JSpinner in Swings    coderanch.com

44. JSpinner problem    coderanch.com

45. JSpinner - disabled foreground color    coderanch.com

> I'm thinking it would get the color from the enabled one? UIManager.getColor("TextField.foreground") gets whatever the 'default' is, so should match the enabled one, but you can specify any color e.g. tf.setDisabledTextColor(Color.YELLOW); there is no real need to put it in the overridden setForeground(). on it's own in the constructor will do - once set, stays that value until changed, regardless ...

46. How to select text in a Custom JSpinner    coderanch.com

> i am using foloowing code for the same but its not working. "but its not working. " implies that it compiles and runs OK, but doesn't achieve the desired result. I couldn't get your version to compile (please show us how you did it), but my version of a 'compiled OK' selectAll() works fine. so, get yours to compile and ...

47. JSpinner serialization/deserialization    coderanch.com

In my application, JPanels are written to files using ObjectOutputStreams. When a panel that includes a JSpinner is written to a file and then read back, the state of the spinner can no longer be changed. I've had no such problems with any other swing components. The current value is ok, it loads correctly the last value i selected on the ...

48. about JSpinner...    coderanch.com

49. JSpinner dateeditor issues    coderanch.com

Hi all, I have several issues with spinners and date editors. The main objectives I have are: a spinner for hours and minutes set foreground color (eg green) while editing set foreground color (eg black) when finished do not allow invalid edits OR set foreground color (eg red) if invalid My first issue is that when I enter a number manually ...

51. Interdepenent JSpinners problem    coderanch.com

Hi, I have two JSpinner which represent the width and the height of an image. These values can be manipulated freely unless "Maintain ratio" checkbox is selected. Then, when e.g. width changes, the height value is changed accordingly automatically using the previously calculated size ratio for the image. This little program represents the idea (I hard-coded the size ratio): import java.awt.FlowLayout; ...

52. JSpinner does not work for Numbers    coderanch.com

Hi, Can you please have a look at the following code to figure out why my customer JSpinner throws a runtime "java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Integer" error ? import java.awt.*; import java.math.BigDecimal; import java.text.NumberFormat; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import javax.swing.*; import javax.swing.text.DateFormatter; import javax.swing.text.DefaultFormatterFactory; import javax.swing.text.NumberFormatter; public class MyNumberSpinner extends JSpinner { SpinnerModel model = null; JComponent editor = ...

53. Remove comma in the JSpinner    coderanch.com

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long at java.lang.Long.compareTo(Long.java:34) at javax.swing.SpinnerNumberModel.incrValue(SpinnerNumberModel.java:335) at javax.swing.SpinnerNumberModel.getNextValue(SpinnerNumberModel.java:355) at javax.swing.JSpinner.getNextValue(JSpinner.java:351) at javax.swing.plaf.basic.BasicSpinnerUI$ArrowButtonHandler.actionPerformed(BasicSpinnerUI.java:640) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272) at java.awt.Component.processMouseEvent(Component.java:6267) at javax.swing.JComponent.processMouseEvent(JComponent.java:3267) at java.awt.Component.processEvent(Component.java:6032) at java.awt.Container.processEvent(Container.java:2041) at java.awt.Component.dispatchEventImpl(Component.java:4630) at java.awt.Container.dispatchEventImpl(Container.java:2099) at java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168) at java.awt.Container.dispatchEventImpl(Container.java:2085) at java.awt.Window.dispatchEventImpl(Window.java:2478) at java.awt.Component.dispatchEvent(Component.java:4460) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) ...

54. How to change jspinner up/down arrows from right to left    coderanch.com

Hi all, If there is any possibility to change right alignment of up/down arrows in jspinner component look to left, or do I have to write my own component? I was trying to sort this problem on my own but it took me a lot of time and after 4h of searching/trying to solve the problem I end with nothing but ...

55. JSpinner Font help.    coderanch.com

I am running a swing application on OS X and I've tried every way I can think of to set the font size of the edit field - but it does not seem to work. jSpinnerQuantity.setFont(Common.font_std); JSpinner.NumberEditor ne = new JSpinner.NumberEditor(jSpinnerQuantity); ne.setFont(Common.font_std); ne.getTextField().setFont(Common.font_std); If the above looks ok to you - could someone else who has access to an OS X ...

56. Finding and using the Jspinner SpinnerNumberModel value    coderanch.com

Hello, I've got a Jspinner that uses the SpinnerNumberModel and goes from 0 to 30 with an incressement of 1. I want to be able to have a changeListener method to find and compare the value. For example, if the user spins the spinner to show the value "3" , then I can do checks on that value to see if ...

58. [HELP]JSpinner Left Alignment    java-forums.org

Hi PhHein I want to apologize, but I don't understand what I have done wrong. Would you please explain to me what I did? If it has to do with the quote on one person's question, then I think I might now what it was all about. I tried to use hyperlinks in order to link threads together, but it didn't ...

59. How to put JSpinners value into an array?    java-forums.org

import javax.sound.midi.*; public class MidiSynthesizerSample { public static void main(String[] args) { int[] notes = new int[]{60, 62, 64, 65, 67, 69}; try { Synthesizer synthesizer = MidiSystem.getSynthesizer(); synthesizer.open(); MidiChannel channel = synthesizer.getChannels()[0]; for (int note : notes) { channel.noteOn(note, 50); try { Thread.sleep(200); } catch (InterruptedException e) { break; } finally { channel.noteOff(note); } } } catch (MidiUnavailableException e) { ...

60. JSpinner resizes, I don't want that.    java-forums.org

Greetings, Suppose I have a JPanel with a FlowLayout. I populate the JPanel with a few JSpinners. They all have a SpinnerListModel with simple Strings. So far there's no problem. Not all Strings in those models are equal in size, neither in the number of characters, nor in their display length. Suppose the current value of a JSpinner is a short ...

61. One Jspinner modifying the value of the other    java-forums.org

Hello, Lets say i have two spinners S1 and S2 with different values ... and when I am going to decrease the value of S2, if this value is fewer than S1, the interface does not allow me to do it. How to do this? Hints? Thank you ! Also I would like that if I increase the value of S1, ...

62. JSpinner getValue method bug in double?    java-forums.org

Hello, I am using a JSpinner with a double model. When retreiving the values with the getValue method some values are retreived incorrectly. For example. If in the JSpinner the value is 0.3, the getValue method retreives 0.300000000004... If it is 0.8 the value is 0.79999999999999 or with 1.9 is 1.900000000000000001 Some values (0.2, 0.3, 0.4) are retreived correctly... What the ...

63. JSpinner problem    java-forums.org

64. Help me! how to use JSpinner    java-forums.org

65. Java GUI using a Jspinner    forums.oracle.com

nick2price2003 wrote: Sorry for keep going on at this subject but i am trying to learn it. How would i put in the values? Would it be like I think that the first and last parameters might be correct, but i am not sure about the middle too. The 17 is supposed to represent 17th of month, i think....I am just ...

66. Using Jspinner in Java GUI    forums.oracle.com