jspinner

Make JSpinner only read numbers but also detect backspace

陌路散爱 提交于 2019-12-17 09:59:00
问题 I'm trying to make a JSpinner that will only accepts numbers but I also want it to read/respond to backspace. public class test { JFrame frame; JPanel panel; JSpinner spinner; public test() { frame = new JFrame("test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(200,200)); panel = new JPanel(); SpinnerNumberModel numSpin = new SpinnerNumberModel(10, 0,1000,1); spinner = new JSpinner(numSpin); JFormattedTextField txt = ((JSpinner.NumberEditor)

Make JSpinner only read numbers but also detect backspace

放肆的年华 提交于 2019-12-17 09:58:04
问题 I'm trying to make a JSpinner that will only accepts numbers but I also want it to read/respond to backspace. public class test { JFrame frame; JPanel panel; JSpinner spinner; public test() { frame = new JFrame("test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(200,200)); panel = new JPanel(); SpinnerNumberModel numSpin = new SpinnerNumberModel(10, 0,1000,1); spinner = new JSpinner(numSpin); JFormattedTextField txt = ((JSpinner.NumberEditor)

Java JSpinner.DateEditor working with TimeZone March clock change

我的未来我决定 提交于 2019-12-13 17:44:01
问题 I have a problem with the standard JSpinner.DateEditor (as probably does everyone else). When it works with the Java.util.Date class, it only gets a default format from the Locale set on the spinner. It appears to be TimeZone ignorant. When we have a Date that is on the March Clock change day which in the UK has no 2 o'clock - the time jumps from 01:59:59.999 AM to 03:00 AM with day light savings applied. Therefore in the JSpinner.DateEditor I do not want the user to see anything for 02:00 to

How can I inform a user that the value he's entered has been constrained to the JSpinner lower bound?

二次信任 提交于 2019-12-13 03:51:45
问题 I need to display an error message and NOT change value of a spinner if user types a value outside of the bounds. If the spinner buttons are used there is no issue. But if user types a number lower than lower bound, the spinner automatically sets it to the lower bound value. Which may be good BUT I need to make sure user is aware. SpinnerNumberModel spin = new SpinnerNumberModel(10, 10, 100, 5); mySpin = new JSpinner(); mySpin.setModel(spin); If user types in 3 the spinner will get set to 10.

How do I know if increment/decrement on JSpinner is pressed?

99封情书 提交于 2019-12-13 03:49:36
问题 I have a few JSpinners and they are numeric values starting at 10 and can be incremented until 99. In my program the user has 15 points to disperse evenly across 6 skills. Every JSpinner has an EventListener to detect if its pressed, but more specifically I need to know which button was pressed so I know which action to take. They dont want to take a point off of strength and have it decrement the Total Points by 1, Instead if the Decrement is pressed it should Add 1. What would be the best

How to 'notice/trap" when user types invalid value when JSpinner loses focus

核能气质少年 提交于 2019-12-13 02:25:46
问题 This is a follow on SSCCE to my previous question: Previous Question This JSpinner background goes RED when users types an invalid value and WHITE when valid. However, if value is invalid and user clicks away from this field the value reverts to whatever was previous. I want to notice/trap when this happens and inform the user that his typed value is NOT being used, and disable any other functions that rely on this value. How can I ammend the following code to accomplish that? public static

Swing change the JSpinner back and fore colors

蓝咒 提交于 2019-12-12 17:41:50
问题 How can I change the background and foreground color of a JSpinner in swing? is there any simple solution except override the paint() method? setting the background or foreground color doesn't work, at least for me. I also tested with all default look and feels, no success. JDK: 1.7.0.51 Win764 Thanks in advance 回答1: The JSpinner is a compound component. Simply said: By default, it conains a JFormattedTextField that shows the value, and two buttons for increasing and decreasing the value. One

JTable with JSpinner Enable/Disable

妖精的绣舞 提交于 2019-12-12 15:38:17
问题 I've got a 3 column JTable. Column 2 is a checkbox which I want to enable/disable the JSpinner for that row. I've got working how I want except for one thing -- The JSpinner doesn't actually look like its disabled (text and spinner buttons greyed out). I'm not quite sure how to attain this. I've tried forcibly calling setEnabled(false) on the JSpinner, but the table doesn't seem to redraw correctly. Here is some code I've gotten working through other StackOverflow examples: import java.awt

JSpinner.DateEditor in Java Not Respecting TimeZone on Initialization

元气小坏坏 提交于 2019-12-12 14:11:13
问题 I'm working on bugfix to an existing Swing Application that is using java dates and the Swing's JSpinner as a DateEditor. I'm trying to get the Editor to default to using UTC to display the time, rather than our local timezone. The application is running on Windows, using Java 8. The code I am using is below. import java.util.Calendar; import java.util.Date; import java.util.TimeZone; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSpinner; import javax.swing

How do I make a JPanel item go under another item in the same BorderLayout?

ぃ、小莉子 提交于 2019-12-12 02:46:36
问题 I am trying to get my JTextField ( desc ) to under the JSpinner , ( dayspinner ) but I'm not sure how. If I put the text field in SOUTH , it just goes all the way to the bottom of the window. I would also like to implement whatever solution there is to this problem with my beginning menu with the 3 buttons next to each other, I would much rather them be on top of one another. import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class Scheduler {