天道酬勤,学无止境

jspinner

Setting Time Format for jspinner in swings

Question 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 am/pm format. i searched in properties but could not get this format. Please suggest me some way to display time in hh:mm am/pm format. I thank to all your valuable suggestions. Answer1 You can set an editor and a date model like this: SpinnerDateModel model = new SpinnerDateModel(); model.setCalendarField(Calendar.MINUTE); spinner= new JSpinner(); spinner.setModel(model); spinner.setEditor(new JSpinner.DateEditor(spinner, "h:mm a

2022-04-26 11:11:10    分类:技术分享    java   swing   time   jspinner

How change format time from jSpinner?

Question I use a jSpinner to choose and save time. I want enter the start time for a task in the database. But the format that saves the database is this: Tue Apr 15 17:24:56 BST 2014 I want in HH:mm. This is the code I use to write the data in the database: public void UpdateTask() { try { Task t1 = new Task(); t1.setIdTask(jTIdTask.getText()); t1.setDate(jTDate.getText()); ----> t1.setHourBegin(jSpinner2.getValue().toString()); // This is what I need change TaskDao dao = new TaskDao(); dao.updateTask(t1); } catch (SQLException ex) { Logger.getLogger(jTTask.class.getName()).log(Level.SEVERE

2022-04-15 18:10:15    分类:技术分享    java   swing   jspinner

Accept measuring units in JSpinner as input

Question I have a numeric JSpinner which accepts values in a specific measuring unit. Now, I'd like to have a special JSpinner behavior: If a user enters a numeric value and appends a specific measuring unit string (e.g. "inch", "pica") then the entered numeric value must be converted into another value (depending on the unit string). This conversion must occur when user leaves the spinner field (focus lost) or if a "commitEdit" occurs in any way. I've tried several variants: Custom document filter, custom format instance and custom text field document for the spinner's JFormattedTextField

2022-04-13 23:43:11    分类:技术分享    java   swing   units-of-measurement   jspinner   numberformatter

How to specify a range of valid values in a Java GUI

Question I am creating an IMDB application which displays and organizes movies found on you computer (by looking up the metadata via an IMDB API). In my search panel I want to give the user the option of looking for movies that were released in a specific range of years (e.g. between 1990 and 2005). Currently I use for this two JSpinners, one for the minimum year and one for the maximum year and use cross validation to check whether maxYear >= minYear && minYear <= maxYear However I don't think this is very user-friendly. What I would like is a JSlider with two knobs, one for min and one for

2022-04-09 02:08:20    分类:技术分享    java   swing   jslider   jspinner   ui-design

How to make a time format in Jspinner?

Question How to make a time format like this hourhour:minuteminute:secondsecond,milisecondmilisecondmilisecond using only one Jspinner when I make this spinner using visual GUI of NET beans. Answer1 You need to use both, SpinnerDateModel and JSpinner.DateEditor with the correct date format pattern: public class JSpinnerDateFormat extends JFrame { public JSpinnerDateFormat() { super("JSpinner Date Format"); JSpinner spinner = new JSpinner(); spinner.setModel(new SpinnerDateModel()); spinner.setEditor(new JSpinner.DateEditor(spinner, "HH:mm:ss.SSS")); add(spinner); pack()

2022-04-03 00:49:19    分类:技术分享    java   swing   jspinner

how can I get the value of a the selected item in a JSpinner?

Question I'm making an application that uses a JSpinner with a max number 30,I should choose a value from this JSpinner and tape a String to the JTextField and the result will appear in the Textarea,when I compile I have many problems concerning the method jSpinner1State,can any one help me because I don't know where is my problem. This is my code of the method JSpinner: jSpinner1.addChangeListener(this); private void jSpinner1StateChanged(javax.swing.event.ChangeEvent evt) { // TODO add your handling code here: Object sp=jSpinner1.getValue(); int i =Integer.parseInt(sp.toString() ); String

2022-04-02 06:40:40    分类:技术分享    java   swing   jspinner   changelistener

JSpinner giving old values

Question I am using couple of JSpinners in my project who display the hour and minutes. When the JSpinner is incremented or decremented i have to save the value to the database. But the problem is that the JSpinners are giving me old values. eg- If the time displayed is 09:30 and i increment the time to 10:30, I am getting 09:30 as the returned value. I am using following code UPDATED SSCCE package spinnerupdation; import java.awt.Container; import java.awt.FlowLayout; import java.text.SimpleDateFormat; import java.util.Calendar; import javax.swing.JFormattedTextField; import javax.swing

2022-03-14 07:03:28    分类:技术分享    java   swing   event-listener   jspinner   changelistener

How to limit JSpinner

Question The valid range for this application is 0 to 9 but there seems to be no NetBeans 7.0.1 JSpinner minimum or maximum value setting. Is there another way to limit the range of this JSpinner to 0..9? Answer1 In my Netbeans 7.3 i followed theese steps: Step 1: Step 2: Step 3: And final step 4: That works for me. Answer2 // from 0 to 9, in 1.0 steps start value 5 SpinnerNumberModel model1 = new SpinnerNumberModel(5.0, 0.0, 9.0, 1.0); JSpinner spin1 = new JSpinner(model1); Answer3 You'll have to use this constructor of SpinnerNumberModel. Snippet: JFrame frame = new JFrame("Limiting value

2022-03-09 11:08:09    分类:技术分享    java   swing   netbeans-7   jspinner

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

Question 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 method to execute this? (Also I am using NetBeans so a bit of the program is autoGenerated.)

2022-02-13 16:08:03    分类:技术分享    java   jspinner

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

Question 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. But I need to confirm with user that this is what he wants. EDIT 1 I coded up TIM B's

2022-02-13 15:26:17    分类:技术分享    java   swing   jspinner