Updating JSpinner display

Hi, I have created a JSpinner that's responsive to the user input by adding a keyListener. The code would check to make sure the user input is valid, or else it would set the user input to the last valid display value. i would like the JSpinner's TextField to change on the fly; however, it seems that the display (JSpinner's Textfield) is never updated properly until Enter key is pressed. I would be greatly appreciated if someone can help out thanks.
public void JSpinnerSampleCode(){
     KeyAdapter listener1 = new KeyAdapter() {
      * Invoked when a key has been typed.
      * This event occurs when a key press is followed by a key release.
     @Override
     public void keyTyped(KeyEvent e) {
               Object source = e.getSource();
          if (source == ((JSpinner.DefaultEditor)daySpinner.getEditor()).getTextField()){
               dayFieldChanged();
     SpinnerNumberModel daySpinnerModel = new  SpinnerNumberModel(new Integer(0),new Integer(0),new Integer(364),new Integer(1));
     JSpinner daySpinner = new JSpinner(daySpinnerModel);
private void dayFieldChange(){
          int tempDays;
       /* please note the variable daysis a global value, declared as int*/
          JFormattedTextField dayTextField =((JSpinner.DefaultEditor)daySpinner.getEditor()).getTextField();
          dayTextField.setEditable(true);
          try{
               if (dayTextField.getText().length() == 0) days = 0;
               tempDays = Integer.parseInt(dayTextField.getText());
               if (tempDays > 365 || tempDays < 0) {
                    throw new NumberFormatException();
               }else{
                    days = tempDays;
          }catch(NumberFormatException e){
               getToolkit().beep();
               String dayDisplay = (new Integer(days)).toString();
               dayTextField.setText(dayDisplay);
               try {
                    dayTextField.commitEdit();
               } catch (ParseException e1) {
                    e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
               dayTextField.setCaretPosition(dayTextField.getText().length());
                        dayTextField.repaint();
               dayTextField.revalidate();
}The repaint() and revalidate() doesn't seem to update to the correct value. For example if I type in 658. The computer would beep to indicate that there is error. The display will not change the dayTextField value ( it will display 658)unless I pressed Enter Key, then it would change to 65. I am wondering is there a way to making it change on the fly, thanks

ok, this is a simplified version of source code. I place the number of character restriction to 2, but when you run the JSpinner, you can see that type in (more than 2 characters). The subroutine never for once enters or calls the CustomizeDocFilter.java's insertString or replace function which supposes to restrict the user input.
import javax.swing.*;
import javax.swing.event.DocumentListener;
import javax.swing.event.DocumentEvent;
import javax.swing.text.*;
import java.awt.*;
public class JspinnerTest extends JDialog {
     private JPanel contentPane;
     private JSpinner spinner1;
     private JButton buttonOK;
     public JspinnerTest() {
          setContentPane(contentPane);
          setModal(true);
          getRootPane().setDefaultButton(buttonOK);
     public static void main(String[] args) {
          JspinnerTest dialog = new JspinnerTest();
          dialog.pack();
          dialog.setSize(100, 100);
          dialog.setVisible(true);
          System.exit(0);
     private void createUIComponents() {
          SpinnerNumberModel numberMd = new SpinnerNumberModel(0, 0, 1000, 1);
          spinner1 = new JSpinner(numberMd);
          JTextField spinnerTextField = ((JSpinner.DefaultEditor) spinner1.getEditor()).getTextField();
          AbstractDocument doc = (AbstractDocument) spinnerTextField.getDocument();
          doc.setDocumentFilter(new CustomizeDocFilter(2));
          DocumentListener lister1 = new DocumentListener() {
                * Gives notification that there was an insert into the document.  The
                * range given by the DocumentEvent bounds the freshly inserted region.
                * @param e the document event
               public void insertUpdate(DocumentEvent e) {
                * Gives notification that a portion of the document has been
                * removed.  The range is given in terms of what the view last
                * saw (that is, before updating sticky positions).
                * @param e the document event
               public void removeUpdate(DocumentEvent e) {
                    //To change body of implemented methods use File | Settings | File Templates.
                * Gives notification that an attribute or set of attributes changed.
                * @param e the document event
               public void changedUpdate(DocumentEvent e) {
                    //To change body of implemented methods use File | Settings | File Templates.
          doc.addDocumentListener(lister1);
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
          $$$setupUI$$$();
      * Method generated by IntelliJ IDEA GUI Designer
      * >>> IMPORTANT!! <<<
      * DO NOT edit this method OR call it in your code!
      * @noinspection ALL
     private void $$$setupUI$$$() {
          createUIComponents();
          contentPane = new JPanel();
          contentPane.setLayout(new GridBagLayout());
          final JPanel panel1 = new JPanel();
          panel1.setLayout(new GridBagLayout());
          GridBagConstraints gbc;
          gbc = new GridBagConstraints();
          gbc.gridx = 0;
          gbc.gridy = 0;
          gbc.weightx = 1.0;
          gbc.weighty = 1.0;
          gbc.fill = GridBagConstraints.BOTH;
          contentPane.add(panel1, gbc);
          gbc = new GridBagConstraints();
          gbc.gridx = 0;
          gbc.gridy = 0;
          gbc.anchor = GridBagConstraints.WEST;
          gbc.fill = GridBagConstraints.HORIZONTAL;
          panel1.add(spinner1, gbc);
      * @noinspection ALL
     public JComponent $$$getRootComponent$$$() { return contentPane; }
}For the CustomizeDocFilter class, I paste it below, but as mentioned in the previous posting. I got this off Sun's website.
import javax.swing.text.DocumentFilter;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import java.awt.*;
* Created by IntelliJ IDEA.
* User: wcw
* Date: 22-Feb-2007
* Time: 3:39:57 PM
* To change this template use File | Settings | File Templates.
public class CustomizeDocFilter extends DocumentFilter {
         int maxCharacters;
         boolean DEBUG = true;
         public CustomizeDocFilter(int maxChars) {
             maxCharacters = maxChars;
         public void insertString(FilterBypass fb, int offs,
                                  String str, AttributeSet a)
             throws BadLocationException {
             if (DEBUG) {
                 System.out.println("in DocumentSizeFilter's insertString method");
             //This rejects the entire insertion if it would make
             //the contents too long. Another option would be
             //to truncate the inserted string so the contents
             //would be exactly maxCharacters in length.
             if ((fb.getDocument().getLength() + str.length()) <= maxCharacters)
                 super.insertString(fb, offs, str, a);
             else
                 Toolkit.getDefaultToolkit().beep();
                  System.out.println("error!!!");
         public void replace(FilterBypass fb, int offs,
                             int length,
                             String str, AttributeSet a)
             throws BadLocationException {
             if (DEBUG) {
                 System.out.println("in DocumentSizeFilter's replace method");
             //This rejects the entire replacement if it would make
             //the contents too long. Another option would be
             //to truncate the replacement string so the contents
             //would be exactly maxCharacters in length.
             if ((fb.getDocument().getLength() + str.length()
                  - length) <= maxCharacters)
                 super.replace(fb, offs, length, str, a);
             else
                 Toolkit.getDefaultToolkit().beep();
                  System.out.println("error!!!");
}I hope it helps

Similar Messages

  • My performance is very slow when I run graphs. How do I increase the speed at which I can do other things while the data is being updated and displayed on the graphs?

    I am doing an an aquisition and displaying the data on graphs. When I run the program it is slow. I think because I have the number of scans to read associated with my scan rate. It takes the number of seconds I want to display on the chart times the scan rate and feeds that into the number of samples to read at a time from the AI read. The problem is that it stalls until the data points are aquired and displayed so I cannot click or change values on the front panel until the updates occur on the graph. What can I do to be able to help this?

    On Fri, 15 Aug 2003 11:55:03 -0500 (CDT), HAL wrote:
    >My performance is very slow when I run graphs. How do I increase the
    >speed at which I can do other things while the data is being updated
    >and displayed on the graphs?
    >
    >I am doing an an aquisition and displaying the data on graphs. When I
    >run the program it is slow. I think because I have the number of
    >scans to read associated with my scan rate. It takes the number of
    >seconds I want to display on the chart times the scan rate and feeds
    >that into the number of samples to read at a time from the AI read.
    >The problem is that it stalls until the data points are aquired and
    >displayed so I cannot click or change values on the front panel until
    >the updates occur on the graph. What can I do to be a
    ble to help
    >this?
    It may also be your graphics card. LabVIEW can max the CPU and you
    screen may not be refreshing very fast.
    --Ray
    "There are very few problems that cannot be solved by
    orders ending with 'or die.' " -Alistair J.R Young

  • How do I update my Display Driver

    How do I update my Display Driver for Mac Book Pro 15" using NIVIDIA GeForce GT 330M.
    ADOBE PHOTOSHOP crashes as the GPU is invalid.

    Try forcing the 2nd GPU using GFX CardStatus.
    Absolutely no idea if that will even work / make a difference, but it would be interesting.

  • Please help. Does anyone have a solution re: After the latest update my display has really huge fonts and is unusable

    After the latest update my display on my iphone has really huge fonts and is unusable.
    I can't even get the swipe bar.

    The easiest way to turn off the zoom accessibility feature is to connect your phone to iTunes on your computer.  In the Summary pane, click the "Configure Universal Access..." button.  On the next screen, under "Seeing", select "Neither" and click OK.

  • MS Access 2013 - There isn't enough free memory to update the display

    In Office 2013, in MS Access, I have only created a few Linked tables & queries, but encountered the following error:
     "There isn't enough free memory to update the display. Close unneeded programs and try again"

    Hi,
    In regarding of the issue, please provide us more information to assist you better.
    Did the error message pop-up with the special Access database or the some other databases?
    If it only happened with the special Access database, it might be caused by the database damaged. Please try to Compact and Repair feature mentioned in the following article:
    https://support.office.com/en-us/article/Compact-and-repair-a-database-6ee60f16-aed0-40ac-bf22-85fa9f4005b2
    Then, we also might check the Linked tables & queries of database, it also might cause this issue. Or you could upload a sample here via OneDrive.
    If the other database also has the issue, please try the method in that
    thread:
    ===
    This might be caused by a corrupt VBA registry key. Open your registry editor by clicking START >> RUN and then type regedit and click ok. Then navigate to the registry key below and delete it. When you try to run the VB editor again a new registry
    key will be created.
    HKEY_CURRENT_USER\Software\Microsoft\VBA
    You'll also want to try booting the PC itself into Safe Mode to see if the problem persists.
    ===
    Hope it's helpful.
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Latest update and display changes

    after the latest update my display changed to higher resolution and when I go inot the preference pane I only show two available resolutions.
    What can I do to fix this
    Thank you for any help

    I tried adjusting the value of layout.css.devPixelsPerPx but that did not help. The only thing that temporarily fixed my display issues was to close Firefox- at that point the screen blacked out and reappeared in full view. As soon as I open Firefox the screen blacks out and reappears showing only a portion of my desktop and all the icons not visible are no longer clickable because the mouse cursor can't reach them.

  • Is there a way to force SpeedGrade to update its display when it fails to?

    I'm on a Retina MacBook Pro, and I've turned of GPU acceleration for SpeedGrade per Adobe's instructions, so it won't crash immediately every time I try to open any sequence.
    But I still have a problem: when I draw a mask on the Primary layer, and click the "Apply grading layer to the inside of the mask" button, most of the sliders I use don't have any effect at all. Until, eventually, the screen updates to show what I've done. But sometimes it just never does.
    And I'm definitely using SpeedGrade correctly; it's just that the display only sometimes updates. I mean, I can drag Input Saturation ALL the way to the right, then toggle the Primary layer on and off a few times...and then suddenly the person's face turns orange. But only after I click around for a while and wait.
    What's wrong? Will these problems go away once GPU acceleration is fixed for Intel Iris graphics on the Retina MacBook Pro? Or...?
    I have to say, frankly, that while I love the idea of SpeedGrade, between (months ago) very, very long waits (literally ten minutes) to open a project via Dynamic Link, to the frequent crashes, to this problem now, that I've never been able to simply use SpeedGrade as intended. Every single time I've opened it in the last year, I've had a string of problems. Meanwhile, while I've had some issues with Premiere, it's generally been reliable and a pleasure to use, just like Media Encoder and many other parts of the suite. So when is SpeedGrade going to get the same bugfixing love the other apps get?
    And in the meantime, what can I do to get SpeedGrade working??

    Speedgrade uses some of similar back-coding to PrPro, but much of it is quite different. So the melding of the two within a Direct - to - Sg link workflow (as it seems you are using) is a bit ... complicated. And clearly still uses more and in some cases specific resources than would be used in either program run alone. That said, there's a couple things that might help you.
    First ... after the "handoff", when you are looking at a Speedgrade UI with your project loaded, close down ALL other apps open, including but ESPECIALLY PrPro. Sg will start up PrPro for you when you click on the icon to save & return to PrPro. This helps a lot of the time.
    Second ... realize that masking within a DL session is ... difficult ... for the program to handle and may overtax your laptop's capabilities. They've improved the abilities of masks to function in DL operation, but it's still not nearly the same as say Sg can do if in a "native" mode ... working your footage within say an EDL style session, where Sg is working on it's own project file, an " ircp-dot" file. A bit more complicate & time consuming to prep for, but might actually work while doing your grading.
    Neil

  • Error in updating and displaying ouput in JSP

    Hi im doing project using jsp files.In part of my project there is vote page and vote result page.
    my vote_page.jsp
    <%@ page import="java.util.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.text.*" %>
    <%@ page import="java.sql.Date" %>
    <%@ page language = "java" %>
    <%! int ctr=0;%>
    <%! String[] songs=new String[10];%>
    <%
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection connect;
    connect=DriverManager.getConnection("jdbc:odbc:RegisterDataSource");
    Statement state;
    state = connect.createStatement();
    String strQuery1 = "SELECT title FROM ItemEJBTable";
    String str;
    ResultSet result1 = state.executeQuery(strQuery1);
    while(result1.next())
    songs[ctr]=result1.getString("title");
    ctr++;
    connect.close();
    catch(Exception e)
    %>
    <form method="GET" action="http://localhost:8000/Music/Vote_result_page.jsp">
    <p align="center">
    <font><b><u>Vote for your favorite song</u></b></font></p>
    <font><b>       Songs</b></font>
    <font> </font> 
    <select size="1" name="Song1">
    <%
    for(ctr=0;ctr<songs.length;ctr++){
    %>
    <option>
    <% out.println(songs[ctr]);}%>
    </option>
    </select></td>
    </tr>
    </table>
    <input type="submit" value="Vote" name="submit">and my vote_result_page.jsp
    <%@ page import="java.util.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.text.*" %>
    <%@ page language = "java" %>
    <%! int voteNum=0; %>
    <%! String selSong=new String();
    %>
    <% selSong=request.getParameter("Song1");
    out.println(selSong);
    String selSong1 = selSong.trim().toString();
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection connect;
    connect=DriverManager.getConnection("jdbc:odbc:RegisterDataSource");
    Statement state,state2;
    ResultSet result1;
    state = connect.createStatement();
    state2 = connect.createStatement();
    String strQuery1 = "update Vote_Info set Number_votes=Number_votes+1
    where itemCode=(select itemCode from ItemEJBTable where title='"+selSong+"')";
    state.executeUpdate(strQuery1);
    String strQuery2="select Number_votes from Vote_Info where itemCode =
    (select itemCode from ItemEJBTable where title='"+selSong1+"')";
    result1=state2.executeQuery(strQuery2);
    while(result1.next())
    voteNum=result1.getInt("NumberVotes");
    out.println(selSong+" got "+voteNum+" votes");
    connect.close();
    voteNum=voteNum+1;
    catch(Exception e)
    %>
    <td width="82%" valign="top">
    <!--Display the number of people who have voted for the song-->
    <p align="left"><font face="Arial" size="3" color="#800000">
    <b><u>You voted for the song:</u></b></font>
    <p align="left"><font face="Arial" size="3" color="#800000">
    <b><%=request.getParameter("Song1")%>
    </b></font></p>
    <p align="left"><%= voteNum %> <font face="Arial" size="3" color="#800000">
    people have voted for this song so far.</font></p>
    <input type="submit" value="OK" name="submit">When i select song_no_1 and click on vote button on vote_page.jsp it directs to vote result page and displays that
    1 person has voted for this song and this vote is not updating on table. When i go again to vote page and vote on song_no_2 it says that "2 person have voted this song" even if it is not voted before.
    I dont no where the problem occurs pls help me for this.

    sorry for double posting because i didnt got reply from first one so i thought that nobody have looked on that topic that's why i done this.

  • MBP early 2010 EFI update, external display no longer functioning

    I just updated my MBP early 2010 to EFI 2.6 and now my external display (U2711 connected via displayport) doesnt display anything anymore. (exactly right after restart without touching anything)
    The monitor tries to show something right after boot but then goes into power saving mode. It worked perfectly the second I updated.
    Any ideas? I already resetted PRAM/NVRAM and I could connect the display successfully by way of HDMI so it may have something to do with the resolution (2.560 x 1.440 (WQHD) or displayport.
    - Lennix

    This solved my problem: http://macosx.com/tech-support/mac/where-are-display-settings-stored/18326.html
    bobw wrote:
    Hi Tony
    First dealmac, now here
    Try trashing these files
    ~/Library/Preferences/ByHost/
    com.apple.windowserver.0030654fec7a.plist
    and
    com.apple.preference.displays.000a27e3cb12.plist
    Bobw - Macosx.com Tech Support

  • Update - Lightbox Display Centering Issue

    Upon updating my Adobe Muse software, it appears its created an issue that effects my lightbox display composition widgets. They don't seems to be centered in the webpage anylonger? Help?

    Hi Mark,
    Unfortunately you hit a bug that causes the lightbox to be off center. This happens if the Target inside the Container for each Composition widget has different strokes for different states.
    Until we release a fix for the bug, please make sure you use the same stroke for all the states of a Target, or do not use a stroke at all for that Target. In your case, the Normal/Rollover/Mouse Down states all have a red stroke, while the Active state has no stroke. You can easily select each Target using Layers panel, and then from the states panel select the Active state and use the delete button from the lower-right corner to clear that state's customizations, including stroke.
    Sorry about the inconvenience. Let us know if workaround fixes the issue for you.

  • Update Illustrator display while ScriptUI window is showing

    Hello everyone!
    When I use a script that utilizes a UIScript window, AI appears to not reflect any visual changes the script makes until I .hide() or .close() the ScriptUI window. For example... if I have a script that draws circles when I hit a "go" button in my ScriptUI window, the circles will not show up until I close the window.
    Is there a way that I can dynamically refresh AI's display from the script (sort of like .update() does with the window)? Or is that not possible?
    Thanks!
    -Mark

    Hi Mark,
    Try .Redraw
    example:
    Set appRef = CreateObject("Illustrator.Application")
    appRef.Redraw
    Hope this helps!
    TT

  • Update item display only

    Hi,
    An item with 'display as' is 'display only' will not be updated (via a process after submit). But it will be updated when it is displayed as 'text field'.
    How come?
    Regards, Robbert

    Hi,
    Though you have not stated it appears you are on Apex4.
    By defaul the display items do not save state. If you want item displayed but the value to be set then edit the item and under setting make save session stae = YES.
    This is the expected behaviour of display items as they default to does not save state.
    Regards,

  • Update not displaying foreign language characters

    I just upgraded to iTunes 9.1 for Windows 7, and now when I open it, the library no longer displays foreign characters (most specifically Japanese and Korean) anymore. It just shows boxes where the text should be. I'm worried that if I re-sync my iPod, it will only display boxes on that, too. Before I updated, everything was working fine and the library had no problem displaying foreign characters. Is there a way to fix this problem?

    Post Author: amr_foci
    CA Forum: WebIntelligence Reporting
    i've the same problem,, but i heared that they added more languages and character sets in the service pack 3
    try to find about SP3,, and if you found that your languages supported then upgrade to it
    regards
    Amr

  • I cant update my display adapters

    hey guys. was on here earlier and someone mentioned to me that i need drivers if i go into device manage, open display adapters, and it says "standard VGA graphics adapter". well it does and that gentalmen seems to have logged and consummed his day with other priorities. so my question is this, how do i update or get download and install these drivers? or change that to something else? an and all help is apprecieated . thx and have a good day guys!
    my model # is g7-2269wm. i must also add im running W7 after my HD failed with w8 for the second time.
    idk if this helps or not but this is ids for standard VGA graphics adapter
    PCI\VEN_1002&DEV_9903&SUBSYS_184B103C&REV_00
    PCI\VEN_1002&DEV_9903&SUBSYS_184B103C
    PCI\VEN_1002&DEV_9903&CC_030000
    PCI\VEN_1002&DEV_9903&CC_0300
                        Fadence

    Hi: Please see my reply to your other post at the link below...I was out most of the day and just got back... http://h30434.www3.hp.com/t5/Notebook-Operating-Systems-and-Software/DRIVERS/m-p/5128026#M298907

  • Approval Center Preview Updates not displaying a populated Views list

    Goal is to be able to add Baseline fields to Preview Updates.
    In trying to edit the view in Approval Center other entries ("change the view of Approval center" and "Adding the baseline (tracking) columns to the Approval Center view") indicate the solution is to use the View in Preview Updates
    and imply that the Tasks Tracking view is the view to update for Preview Updates.
    However, the view that I am seeing in Preview Updates does not
    match any view within Manage Views, including Tasks Tracking.
    The Preview Updates displays the following columns:
    ID
    Mode
    Task Name
    Previous Duration
    Duration
    Previous Start
    Start
    Previous Finish
    Finish
    Baseline Work
    Work
    Previous % Complete
    % Complete
    Resource Name
    The Tasks Trackingview already includes Baseline Start/Baseline Finish (and other differences) ... so not the view being used.
    Within Project Center after selecting a project and then selecting Schedule the view list has all expected views defined in Manage Views > Project. 
    But within Preview Updates the View drop down does not invoke a list of views.  So now I am wondering if this is the root problem for this issue I am having.
    Cheryl

    Hi Cheryl,
    I just tested your concern in my Project Online instance. As far as I know, there are no significative changes in the preview updates feature between 2010 and 2013 versions.
    As I said in your previous post, you are several views available in the "preview updates" page (unfortunately in french).
    Those views are the project views that are not related to resources and assignments, meaning all the "... tasks" project views should be available in the preview updates page. Then just edit one of those view adding your fields and save it.
    I tried to edit the task summary project view, adding a few field like bsaeline start and finish and it worked perfectly. Note that each field impacted by the update will be duplicated, for example the start date will be duplicated to a "previous start date"
    field.
    Hope this helps,
    Guillaume Rouyre, MBA, MCP, MCTS |

Maybe you are looking for

  • Civil 3D 2011 Drawing file layers are off but show up in preview and final PDF

    I am using a Windows 7 64-bit,  Acrobat 10.1,  Autocad Civil 3D 2011 In a site plan drawing we are trying to create PDF's of files that have xref's attached. The title block (an xref) is in paper space and the site plan xref is in model space. When t

  • 2.16 GHz Intel Core Duo/ 2GB ram upgrade ?

    Please could someone tell me if I can upgrade my MacBook Pro 2.16 GHz Intel Core Duo/ 2 GB SDRAM running 10.6.8 to Lion as I need it to run some 2015 software ?  IF I can, what are the dangers I must look for and will my laptop then be even slower th

  • My iTunes doesn't have all the icons for categories,how do I get them?

    I have a new iPad with the pre loaded iTunes but along the botto where it should have all the icons such as music videos etc, mine onyhas podcasts, iTunes u and downloads. How do I get the other icons there to download music etc? Please help!

  • Location services in notification center

    I Want to see how long it takes to get home in my notification center, i have location services on, i have "next destination" on, i have added my home address to my info in contacts, I have "frequent locations" on. Please help me?!

  • Master-Details Link

    Hi, I have done master details in obiee 11g,since when i am trying with dimension column its working fine,where my requirement is how to achieve master details link in hirerchial column,in 1st report i have kept product hirerchial cloumn with 1 measu