SetDocument doesn't seem to work correctly

I'm obviously using the setDocument method for my JTextField incorrectly, but how? The DocumentSizeFilter works correctly, allowing only the number of characters I specify, but the DigitDocument.insertString(...) doesn't seem to work at all (it should allow for only digits to be entered into the JTextField).
          AbstractDocument doc;
          pafTextField = new JTextField();
          pafTextField.setDocument(new DigitDocument());
          pafTextField.setPreferredSize(new Dimension(30, height));
          doc = (AbstractDocument)pafTextField.getDocument();
          doc.setDocumentFilter(new DocumentSizeFilter(2));The DigitDocument class:
public class DigitDocument extends PlainDocument{
     public DigitDocument(){
          super();
     public void insertString(int offs, String str, AttributeSet a) throws BadLocationException, NumberFormatException{
          try{
               System.out.println("String str = " + str);
               int i = Integer.parseInt(str);
               super.insertString(offs, str, a);
          catch(NumberFormatException e){
               // do nothing because a user input was not a digit
               Toolkit.getDefaultToolkit().beep();
}the DocumentSizeFilter code:
http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/DocumentSizeFilter.java

didn't try the abstract doc, but why not combine the two
something like this
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
class Testing extends JFrame
  public Testing()
    setLocation(400,300);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JTextField tf = new JTextField(new DigitDocument(2),"",10);
    JPanel p = new JPanel();
    p.add(tf);
    getContentPane().add(p);
    pack();
  public static void main(String[] args){new Testing().setVisible(true);}
class DigitDocument extends PlainDocument{
  int maxChars;
  public DigitDocument(int chars){
    super();
    maxChars = chars;
  public void insertString(int offs, String str, AttributeSet a) throws BadLocationException, NumberFormatException{
    try{
      System.out.println("String str = " + str);
      if(this.getLength()+str.length() > maxChars) throw new NumberFormatException();//<----
      int i = Integer.parseInt(str);
      super.insertString(offs, str, a);
    catch(NumberFormatException e){
      // do nothing because a user input was not a digit
      Toolkit.getDefaultToolkit().beep();
}

Similar Messages

  • Hi I'm running Addressbook and cannot clear previous entry easily when searching my data base of around 5,000 contacts.    I prefer to view in All contacts on a double page spread with details on the right page.  Searching doesn't seem to work correctly i

    Hi I'm running Addressbook and cannot clear previous entry easily when searching my data base of around 5,000 contacts. 
    I prefer to view in All contacts on a double page spread with details on the right page.  Searching doesn't seem to work correctly in this view.
    It's always the second search that is problematic.
    I've tried typing over and all it seems to do is confine the search to the the entries that have come up for the previous search.
    I've tried to use the x to clear the previous entry and then type the next search, same problem.  The only way seems to be to move from "All Contacts" to "Groups".  Then the searched name appears and I can return to All Contacts to see full details.
    Surely three key press' are not the way it's supposed to work?
    FYI
    Processor  2.7 GHz Intel Core i7
    Memory  8 GB 1333 MHz DDR3
    Graphics  Intel HD Graphics 3000 512 MB
    Software  Mac OS X Lion 10.7.3 (11D50d)
    Address book Version 6.1 (1083)
    MacBook Pro, Mac OS X (10.7.1), 8Mb RAM 2.7Ghz i7

    AddressBook experts are here:
    https://discussions.apple.com/community/mac_os/mac_os_x_v10.7_lion#/?tagSet=1386

  • Numbers application on Ipad, the 'VALUE' function doesn't seem to work correctly on the string/text I want to convert to a value.

    Hi, I would appreciate if someone could assist with the following.  On the Numbers application on my Ipad, the 'VALUE' function doesn't seem to work correctly on the string/text which I want to convert to a value.  It gives me an error (in my example: 'VALUE requires a string specifying a number, but found "-14308.65" instead.'
    The exact same document (if converted from Numbers to excel), displays the converted string/text correctly in MS Excel as a value though.

    click on the cell then in the formula bar and use the arrow keys to move the cursor to see if there are any other characters in the cell that could confuse the function.  Also make sure the localization for your country is correct in System Prefs.
    Maybe copy the EXACT contents of the cell and post here.

  • Automator Workflow as Finder Plug In Doesn't Seem to Work Correctly

    Has anyone noticed that if you create an Automator Workflow as a Finder Plug-in in Leopard it does not seem to work correctly or at all?
    I have a two action Workflow.
    1. Get Selected Finder Items
    2. Import Files into iPhoto
    When run inside Automator, it works fine. If I save as Finder Plug-in and use it in the Finder, it gets to the second action and dies.
    I've seen other posts about Finder Plug-in weirdness and was wondering if this was another symptom.

    Yes, I found this out today. Any Finder Workflow that I start with "Get Selected Finder Items" does not work. Hope they fix this soon ...that's an important one to work.

  • Screen saver with "music on" doesn't seem to work correctly for me.  why?

    I don't understand what is going on with the screen saver when I have it set to work when music is "on."
    My photos will play just fine if I manually pick them to play (i.e. a slide show). But when music is playing, and the screen saver begins to activate after the apppropriate time, I either get some "jibberish" writing in the bottom left corner or I get a solid colored white or black screen.
    I've double checked that I have my photos selected correctly. And this was working correctly months ago. I just don't understand what could be causing this now.
    Any thoughts? Thanks.

    Hi, I have a similar problem. When playing music, the screensaver has stopped working. Instead all I get is a white screen. I have checked all the settings and they are ok. The photos show and the albums show will work. But as soon as I switch back to slideshow I get the white screen back. It is even like this in 'Preview'.
    Have you solved the problem now. If so, how?
    Anyone else affected? I took a new software update to the Apple TV two days ago. Could this be the problem?
    all advice welcome
    regards
    Michael

  • Safari on my iPhone 6 running 8.02 doesn't seem to work right. Some Java scripts don't show correctly and they do on other browsers I have downloaded. I tried almost everything and nothing seems to work to fix it. Please help.

    Some websites like the one of my college uses JavaScripts and they seem to load correctly to a certain point but then not really. For example in one it would say select an option from the left menu. And I do it hut nothing happens. But when I go to the same website in another browser on my phone. The JavaScript works completely and allows me to see whatever I was clickig on that menu. I have seen that there are other websites being affected too. I tried clearing my cookies and data. even restarted my phone. And doesn't seem to work. I don't know how change the configuration any more to make it work like normal. At first I thought it was my school's website but it never got fixed. And now I realized is my safari browser! I wanna keep using it since I am really familiar with It. If someone knows how to fix this please let me know!
    Thanks

    You can reset the SMC and see if that helps. If it's a unibody or Retina, follow the method for "a battery you should not remove yourself."
    http://support.apple.com/kb/ht3964

  • Hi everyone,I'm having a problem with my iPhone 5 it's wifi doesn't seem to work.it started yesterday afternoon.

    Hi everyone,I'm having a problem with my iPhone 5 it's wifi doesn't seem to work.it started yesterday afternoon.anyone know what happened?? I'm using 6.0.2

    First thing to try is to reset your device. Press and hold the Home and Sleep buttons simultaneously ignoring the red slider should one appear until the Apple logo appears. Let go of the buttons and let the device restart. See if that fixes your problem.
    If that doesn't correct the problem Make an appointment at an Apple Store to have your device examined by a technician. Or contact Apple Support.

  • My iPhone 5 randomly shutdown and rebooting doesn't seem to work for me, what should I do?

    It also happens when I'm charging my phone, and also the battery percentage doesn't show that correct battery level not unless I turn off and on.. I tried rebooting the phone but it doesn't seem to work for me, random shutdown still happens..

    Will not turn on, will not turn on unless connected to power, or unexpected power off
    Verify that the Sleep/Wake button functions. If it does not function, inspect it for signs of damage. If the button is damaged or is not functioning when pressed, seek service.
    Check if a Liquid Contact Indicator (LCI) is activated or there are signs of corrosion. Learn about LCIsand corrosion.
    Connect the iPhone to the iPhone's USB power adapter and let it charge for at least ten minutes.
    After at least 30 minutes, if:
    The home screen appears: The iPhone should be working. Update to the latest version of iOS if necessary. Continue charging it until it is completely charged and you see this battery icon in the upper-right corner of the screen . Then unplug the phone from power. If it immediately turns off, seek service.
    The low-battery image appears, even after the phone has charged for at least 20 minutes: See "iPhone displays the low-battery image and is unresponsive" symptom in this article.
    Something other than the Home screen or Low Battery image appears, continue with this article for further troubleshooting steps.
    If the iPhone did not turn on, reset it while connected to the iPhone USB power adapter.
    If the display turns on, go to step 4.
    If the display remains black, go to next step.
    Connect the iPhone to a computer and open iTunes. If iTunes recognizes the iPhone and indicates that it is in recovery mode, attempt to restore the iPhone. If the iPhone doesn't appear in iTunes or if you have difficulties in restoring the iPhone, see this article for further assistance.
    If restoring the iPhone resolved the issue, go to step 4. If restoring the iPhone did not solve the issue, seek service.

  • Bridge Offset Nulling Doesn't Seem to Work With SCC-SG24

    Does anyone know if the DAQmx "Perform Bridge Offset Nulling Calibration" vi works with the SCC-SG24 modules?  We have used our NI-9237 module in the past to acquire dual-channel load cell (thrust & torque) measurements, and calling that vi does a fine job of zeroing out the values before applying the load.  However, it doesn't seem to work when we try to take the same measurements using an SCC-SG24 module.
    We are able to zero the values manually, by using the nulling resistors and potentiometers in the SCC-SG24.  But, whether the nulling resistors are installed or not, we are not able to zero the values using the "Perform Bridge Offset Nulling Calibration" vi.  Running that vi does induce a significant offset in the values, but it is not the correct offset needed to bring the values to zero.  For example, with no load applied, a torque reading before running the vi may be +1090 in-lbs, and be "zeroed" to -465 in-lbs after running the vi.  Running the vi multiple times (to check repeatability) always brings us back to approximately -465 in-lbs.
    An additional issue (not sure if it's related or not) is that if we try to run this vi to offset just one of the channels in the task (such as just thrust, but not torque) it will still induce a small offset in the other channel, which doesn't seem right.
    I guess I'm not clear on whether the subject vi is performing an operation on the hardware, the software, or both, so I'm not sure whether the SCC-SG24 modules may not be compatible with this vi?
    Thanks for any help you can provide.

    Hello Dhruser1,
    I think that the DAQmx Perform Bridge Offset Nulling Calibration should work for the SCC-SG24 module.  Take a look at this article:  Removing Large Initial Offset for Load Cell or Strain Measurements with SCXI-1520 or PXI-4220 in particular it mentions that using this VI in addition to the auto zero can introduce an offset.  If you're doing both these is likely the cause.
    Also, when you specify specific channels using the channels input are you also setting the "skip unsupported channels to false?  If not this may be why it affects other channels.
    I hope this helps, and if not please feel free to post back with an update after trying these things.
    Cheers,
    Brooks

  • Data Detection in Calendar in Mavericks doesn't seem to work anymore.

    Since the upgrade to Mavericks, data detection doesn't seem to work anymore.
    Before i just typed in a new event:
    "Meeting XY at 7pm in Berlin"
    and ical would automatically change that to "Meeting XY" and insert the time in the appropriate field and the same for the location.
    Now it doesn't work anymore and i have to insert it manually in the different fields.
    Anyone with the same problem? and maybe a solution?

    After searching a bit longer, I found a solution that worked for me. A setting in the CUPS server needed correcting. See this page for instructions: http://www.macintouch.com/readerreports/printing/topic2807.html#d21jul2008
    After removing the Deny line indicated in the link above, I removed the printer from the remote computer and then added it back it. Two things happened, first when adding the printer back in, I no longer got the generic postscript printer driver as the default, but got the correct Officejet Driver. Second, It worked! Now to try it with my old 10.4.x powerbook to see if it's solved there too.
    Hope that helps!
    David
    Message was edited by: chopp

  • Hibernate hbm2ddl.auto create-drop doesn't seem to work in 10.3 JPA

    Greetings,
    I'm migrating an JPA application from JBoss 5.0 to WebLogic 10.3. In order to simplify the problem, I have the following entity:
    package fr.simplex_software.p204.domain;
    import java.io.Serializable;
    import javax.persistence.*;
    @Entity
    @Table(name="AUTHOR")
    public class Author implements Serializable
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name="AUTHOR_ID", nullable=false)
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    public Long getId()
    return id;
    public void setId(Long id)
    this.id = id;
    I also have the following persistence.xml file:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="p204-ejbPU" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:/jdbc/TestDS</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
    <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
    </properties>
    </persistence-unit>
    </persistence>
    When I deploy the application in JBoss 5.0, the table AUTHOR is created. When I deploy the same in WebLogic 10.3, the table isn't created and nothing happens. Should I do anything of special ?
    Many thanks in advance for any help.
    Kind regards,
    Nicolas

    Hi Matt, thanks for your reply. Yes, I did. Actually I'm testing the JDBC data-source in WebLogic console and the test is successfull. Also, exactly the same app correctly deploys in JBoss. In the WebLogic console I can see my EAR deployed, I'm running some standalone clients against some SLSB in the EAR and they work properly and I'm sure that if I'm manually creating the data-model, the JPA entities will work. The only thing which doesn't seem to work is the automatically data-model creation. I thought that Hibernate may not be so intimatelly integrated with WebLogic as with JBoss and I tried to use Kodo, but I didn't find any auto create-drop equivalent feature. I continue digging but stiil interested by any suggestion, if any.
    Many thanks in advance,
    Nicolas

  • Is it possible to use a Script within an action? - it doesn't seem to work...

    Is it possible to use a Script within an action? - it doesn't seem to work...
    I'm using the 'round any corner' script from SATO Hiroyuki..., and  I'd like to apply it to only one anchor point (on multiple boxes)

    An Action can call a script from the File>Scripts menu by means of the Add Menu Item Action step. But it will only work for the duration of your Illustrator work session. If you quit AI and then restart it, the Add Menu Item step will be blank. This bug has been reported for FOUR FULL VERSIONS of this sloppy program.
    However, if I am correctly understanding your description of what you are trying to automate, an Action will not be able to automate the selection of a particular anchorpoint in multiple paths. You'd have to make the selections all at first. Whether the script would then apply as desired to each path depends on how the script is written.
    JET

  • Copy items to the iPhoto Library option doesn't seem to work

    Hi, I'm using 7.1.1 and if I:
    1. De-select the create "Copy items to the iPhoto Library" option in Preferences/Advanced
    2. Create a new library
    It doesn't seem to work. The images are still being copied into the library -- that is, if I show the package contents of the library, the data directory has the photos. Additionally, if I do something like open, modify in photoshop and save one of the imported files, it doesn't show up in iPhoto. Likewise if I modify the file in iPhoto and then look at the photo in the file system using Preview or Photoshop, the iPhoto changes don't appear.
    Is this a bug? Is it not supposed to work like this? I believe that if I say "don't copy the files into the library" it means that it uses my original photos in their original location and that changes I make in iPhoto modify and manipulate the original files.
    I've tried this on two different machines and get the same results. Anyone have any ideas?
    Thanks!

    markand:
    Welcome to the Apple Discussions. It's not a bug. You don't understand correctly how iPhoto works in the "referenced" library mode. The Data folder contains the thumbnail files that iPhoto creates and needs to operate. The Originals folder will contain alias files linked to the source files at their location. Any edits, by iPhoto or by Photoshop configured correctly will result in a modified file in the Modified folder of iPhoto. *You should not open, rename, move or edit any file in the library package from the Finder.*
    Using Photoshop to edit photos in iPHoto must be done by selecting PS as the editor to use in iPhoto's General Preferences section. Then follow the instructions below to edit photos correctly:
    Using Photoshop (or Photoshop Elements) as Your Editor of Choice in iPhoto.
    1 - select Photoshop as your editor of choice in iPhoto's General Preference Section's under the "Edit photo:" menu.
    2 - double click on the thumbnail in iPhoto to open it in Photoshop. When you're finished editing click on the Save button. If you immediately get the JPEG Options window make your selection (Baseline standard seems to be the most compatible jpeg format) and click on the OK button. Your done.
    3 - however, if you get the navigation window that indicates that PS wants to save it as a PS formatted file. You'll need to either select JPEG from the menu and save (top image) or click on the desktop in the Navigation window (bottom image) and save it to the desktop for importing as a new photo.
    This method will let iPhoto know that the photo has been editied and will update the thumbnail file to reflect the edit..
    If you want to use both iPhoto's editing mode and PS without having to go back and forth to the Preference pane, once you've selected PS as your editor of choice, reset the Preferences back to "Open in main window". That will let you either edit in iPhoto (double click on the thumbnail) or in PS (Control-click on the thumbnail and seledt "Edit in external editor" in the Contextual menu). This way you get the best of both worlds
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • HT201322 The hide your purchase doesn't seem to work on my iPad mini in iBooks, can anyone help?

    The hide your purchase doesn't seem to work on my iPad min, ipad or iphone 5i in iBooks, can anyone help? Is the info on the apple site wrong?

    The info on that is correct - it says :
    You currently cannot hide purchases on devices using iOS 6.
    You should still be able to hide ibooks via your computer's iTunes, and they shouldn't then appear in the Purchased tab in the ibookstore in the iBooks app (if you don't want ibooks that are in the cloud to show on the bookshelf in iBooks then set Settings > iBooks > Show All Purchases 'off' - hiding doesn't hide them from that, only from the Purchased tab).

  • Shuffle songs doesn't seem to work on my ipad mini

    Shuffle songs doesn't seem to work on my ipad mini; it just goes on to play the next alphabetical song. Can anyone help?

    The info on that is correct - it says :
    You currently cannot hide purchases on devices using iOS 6.
    You should still be able to hide ibooks via your computer's iTunes, and they shouldn't then appear in the Purchased tab in the ibookstore in the iBooks app (if you don't want ibooks that are in the cloud to show on the bookshelf in iBooks then set Settings > iBooks > Show All Purchases 'off' - hiding doesn't hide them from that, only from the Purchased tab).

Maybe you are looking for