Prevent a character from showing up in textfield

Hi,
I have a textfield..and the max # of characters allowed should be 15....so how can I stop the user from being able to enter any more characters after 15?
I tried the keyPressedEvent(KeyEvent e) {
if (fifteencharacters == true)
e.consume();
but it doesnt work.
thanks

The DocumentSizeFilter class is straight out of the tutorial.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class FilterTest
    public static void main(String[] args)
        JTextField filterField = new JTextField(16);
        AbstractDocument doc = (AbstractDocument)filterField.getDocument();
        doc.setDocumentFilter(new DocumentSizeFilter(15));
        JTextField plainField = new JTextField(16);
        JPanel north = new JPanel();
        north.add(filterField);
        JPanel south = new JPanel();
        south.add(plainField);
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setJMenuBar(getMenuBar());
        f.getContentPane().add(north, "North");
        f.getContentPane().add(south, "South");
        f.setSize(300,200);
        f.setLocation(200,200);
        f.setVisible(true);
    private static JMenuBar getMenuBar()
        JMenu edit = new JMenu("edit");
        edit.add(cut);
        edit.add(copy);
        edit.add(paste);
        JMenuBar menuBar = new JMenuBar();
        menuBar.add(edit);
        return menuBar;
    private static Action cut = new TextAction("cut")
        public void actionPerformed(ActionEvent e)
            getFocusedComponent().cut();
    private static Action copy = new TextAction("copy")
        public void actionPerformed(ActionEvent e)
            getFocusedComponent().copy();
    private static Action paste = new TextAction("paste")
        public void actionPerformed(ActionEvent e)
            getFocusedComponent().paste();
* A 1.4 class used by TextComponentDemo.java. From java turorial.
class DocumentSizeFilter extends DocumentFilter
    int maxCharacters;
    boolean DEBUG = false;
    public DocumentSizeFilter(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();
    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();
}

Similar Messages

  • Prevent Spry Tags from showing on page

    I have looked, but could not find a similar topic.
    My question is, is there a way to prevent spry tags from
    showing on a page when it loads or gets refreshed?
    Example:
    http://www.sothebys.com/video/viewer/
    When first coming to the page, the spry tags appear, once the
    page is loaded they are replaced by it's content. Same happens when
    the page is refreshed.
    Any suggestions?

    Hi,
    Check out this sample:
    http://labs.adobe.com/technologies/spry/samples/data_region/HideDataReferencesSample.html
    Thanks,
    Don

  • Preventing AIR Windows from showing up in the taskbar

    Is it possible to prevent a normal type window from showing
    up in the taskbar? I would like the normal window systemchrome on
    my windows but want them to act like a utility type window. Any
    help is appreciated.
    Mike

    bump

  • Prevent Personal Sites from showing in search

    Is there a way to prevent the personal site from showing in search results?
    It seems to only happen for certain users
    I dont want /personal/username to appear in search results
    thanks
    themush

    Or slightly simpler, remove them from the local SharePoint content source.
    Having said this, do you really want/need to remove these results? They will only appear when a user has permission to see the files in question and those results are thought to be relevant. That's why you're getting spotty appearance of them in the results.

  • How can I prevent Podcast Maker from showing direct link to media files?

    I'm brand-new to podcasting and to Podcast Maker for Mac, but I finally created a podcast (after 3 hours of trying to figure out how to get the thing to upload to the correct sub-directory).
    My question is: When I look at my feed in Firefox, I see so-called 'media links' to all my original mp3's, as well as the links I specified to the web pages where the mp3's are embedded inside my site content.
    Is there anyway to keep those media links from showing up in the feed? If people access my mp3's directly without visiting my website, it defeats the whole purpose for me creating the podcast in the first place.
    Thanks for any help!
    Brian

    I think I may have to look into a redirect line in my htaccess file so that direct loads of my mp3's route through my website page.
    If you do this you may find iTunes won't read the files, so I should test carefully on one file first if possible.

  • Possible to prevent hidden slide from showing on "next" click?

    I am working on my first Captivate 7 project. I have created a sub-set of slides that users will be able to link to from another slide (almost like pop-up boxes). This is optional content, so I don't want to force users to view it. How do I prevent a slide from displaying when the user clicks "Forward"? I figured out how to exclude it from the TOC, but if I actually Hide the page, I can't use the Jump to Slide feature.
    I tried to set up an OnExit action to jump to another slide, but that doesn't seem to work either. I'm sure others must do this all the time? I really appreciate your advice!!

    You need to set up custom variables that track whether or not the slide should be seen.  The default value will be that the slide is NOT seen (ie 0 or False).  The On Slide ENTER event for these 'hidden' slides will execute a Conditional Advanced Action that checks the value of the variable and if it is set to 0 or False then it will jump immediately to the next slide.
    When you deliberately jump to that slide from another slide your jump action needs to be executed by an Advanced Action that first sets the value of the variable to 1 or True before jumping.  This way, when it gets to the slide the On Slide Enter event's action will see that the slide is supposed to be viewed and allow it to play.
    To clean up, you need to ensure that any way the user gets out of that same slide will also execute an action that resets the variable to 0 or False again.

  • De-cluttering tip: Is there a way to prevent a track from showing up under "Artist" while still being able to view the artist info when I play the song by Album?

    I asked this question here:
    https://discussions.apple.com/message/15312099#15312099
    It was suggested I re-post in this forum, seeing as the problem may be specific to the Touch.
    So, I have lots of "compilation" albums that include songs by various artists (for example, Pitchfork's top 500 singles of the decade). I usually select my music by "Artist," and now my ipod is super cluttered, because now I have hundreds and hundreds of artists listed, many of which I only have one or two songs by from this compilation.
    One solution: simply delete the artist information for these large compilations, and then the songs from the compilations will no longer show up under "Artists." Problem is, I would like to know who the artists are when I play the compilation (I simply don't want to have the artists listed under "Artists")
    Another solution: I could manually delete the artist info, but paste that info on to the song name. For example, a track that once looked like:
    Artist: Nirvana
    Title: Smells Like Teen Spirit
    Album: Best of the '90s
    After my editing, would look like:
    Artist: [blank]
    Title: Nirvana - Smells Like Teen Spirit
    Album: Best of the '90s
    This would solve my problem...but it would literally take hours to do for each and every individual song. Not practical.
    Does any one have any other suggestions? It seems like there would be a way to just check a box for what info you want to be listed (ie, I could un-check "Artist," and then the song would no longer be listed by Artist, even though the Artist information would still be retained for reference). Does this option exist?
    In the prior thread, someone suggested I mark it as a "compilation" in iTunes. But that did not prevent the individual artists from being listed under "Artists." Someone suggested that I may need to turn "Compilation" to "On" on my iPod. But that does not seem to be an option on the Touch.
    Suggestions?
    Thanks!!

    So, I have lots of "compilation" albums that include songs by various artists (for example, Pitchfork's top 500 singles of the decade). I usually select my music by "Artist," and now my ipod is super cluttered, because now I have hundreds and hundreds of artists listed, many of which I only have one or two songs by from this compilation.
    Why not set the iPod to show Compilations?
    In Settings select Main menu (or Music menu) and check Compilations. (You can do so for both if you desire.)
    Now all of the Artists that only appear in compilation albums won't appear in Artists.
    To get to the Artists that only appear in compilation albums open Compilations in your Main Menu or Music Menu (or either).

  • Preventing input form from showing existing record

    Hello,
    I'm creating a series of web pages to collect info from a user. On the first page, create.jsp, I have a CommandLink bound to the Create binding action. It forwards to the input form on its own page, form.jsp. The defaults (sequence number, creation date) from the model layer appear nicely in the form. If the user follows the page flow, the record is committed and everything is swell.
    The problem is that users can enter "form.jsp" directly into their location bar in their web browser, and the input page will display the first record in the table. I cannot use an authorization scheme to prevent access because any general user of the web should be able to input their info. (In other words, you can't be logged-in before creating your login.)
    How can I disable this? Or, is there a hook in the processing lifecycle that I can use to determine if a user has created a new row before displaying the input form?
    I'm using JDev 10.1.3 production, ADF Faces, ADF BC.
    Thanks,
    -Anthony

    I figured this out myself, actually this was quite simple.- just set the 'immediate' property on the component (button) to 'true'.

  • Prevent parked documents from showing in Liquidity Forecast

    We have an invoice scanning system in place here which usually leads to many parked invoices being created. These invoices then show up in the liquidity forecast when we would like to exclude them. Many of these parked documents need to be reviewed to ensure the amounts, accounts, etc are correct from the initial OCR scan. We would only like to see the posted documents show in FF7A.
    Is there a standard way to accomplish this? Thanks in advance!

    When drilling down into line item you can exclude/ fitlern them out. More seems not to be possible in standard.
    Regards
    Hein

  • Bonjour issues preventing Apple TV from showing up in itunes?

    After hours of trouble-shooting and trying out pretty much every fix suggested in this forum and others to make my brand new AppleTV show up in iTunes I think I found something useful. Apple TV uses the Bonjour protocol to make itself known to other systems on the local network. A utility called Bonjour browser shows all the multicasting services on the local network..and voila, AppleTV is broadcasting and showing up in the browser on my MacBook. Issue is, with the AppleTV broadcast I'm getting a "can't resolve link-local name" error message. In fact, I'm getting that error for every device listed in the Bonjour browser. Another tool that I read about in a blog (Bonjour Conformance Test) fails to complete the test (probing failure).
    I know more about Bonjour now than I ever wanted to know but still feel completely clueless. Hey, these are APPLE products, this is supposed to be EASY Any ideas what's going on here?
    DANKE!

    I wouldn't worry about the 'can't resolve......' message, the fact that the browser application has seen the tv means that the tv is advertising it's services. Bonjour does nothing more than this, it does not enable or allow sharing, it merely advertises that a device can share.
    It might be worth checking that itunes is also advertising it's sharing properly, you should be looking for something like itunes DAAP, which is the protocol itunes uses to share its library.
    Moving on slightly, I recently did some tests and found that it is possible to stream to 3 tv's and 3 other macs from a single library, to cut a long story short, this doesn't fit in with my understanding of DAAP which limits sharing to 5 devices. My conclusion is that itunes doesn't use DAAP to share with the tv. If this is correct itunes needs to advertise another sharing service over bonjour specifically for the tv, so you should see another service advertised in the application you are using, let's say itunes-appletv, although it is likely something different.

  • How to prevent a window from showing up when a program is launched

    Hi guys!
    I'm looking for a way to make run a program in an invisible way..
    I've managed to hide its icon from the dock, but I cannot avoid its maining window appearing when it opens...
    Could I solve this trouble by deleting some lines in the info.plist file?
    Thank you in advance!
    PS Someone posted the same question some moths ago,
    here:
    https://discussions.apple.com/thread/2630616?start=0&tstart=0
    but if I delete
    <key>NSMainNibFile</key>
              <string>MainMenu</string>
    the program doesn't work!!

    please define what you mean by 'in an invisible way', and please tell us what application you're talking about.  and it's really not a good idea to delete the reference to the nib file, because the nib can store a lot of information the program needs.
    you probably want to set either the LSUIElement key to 0 or the LSBackgroundOnly key to 1 in the info.plist file. The first can show windows at need, but doesn't otherwise show to the user; the second never shows anything to the user.  However, either might interfere with the operation of the app, depending on what the app is designed to do, and doing this might break the code signature for the app which will make the app un-openable until you reinstall the original.
    if you just want an app to open invisibly at boot time, that's a different issue.

  • HT201304 How to prevent the poster/icon of explicit movies from showing up in the Top Hits list

    Although i have setup up all the parental controls to prevent adult/explicit content in the movies (Apple TV), still the posters of adult movies often show up in the Top hit List, is there a way to prevent the poster from showing up in the list too ?

    Use VMware Fusion? But seriously, Fusion does what you want. It just puts a mini VM control menu at the top when running full screen (and that's configurable, too), so the main menu bar doesn't appear at all. Which means that it's up to Parallels to handle this. Are you running Parallels 7, which is designed for Lion? If you are and Parallels still doesn't offer something similar, you need to contact Parallels.

  • Preventing page from showing up in Site Map

    Is there no way to prevent a page from showing up in the site map? Even if I disable a page it still shows up in the site map.

    Hey Brad,
    You need to wait till the end of the day for the sitemap to update. If it existed before and in the sitemap.xml when off it will not render.
    You can now also go into the sitemap.xml manually via FTP and change things. I think if you do that it stops auto updating though so if you want that to kick in, deleting it and then it will be auto generated again by the system.
    Site map in the admin is for the page list you insert and doing child/parent stuff for breadcrumbs.
    That make sense?

  • How do I prevent items from showing up under "Available Software" in the software center after they have been removed?

    I have some scenarios where I want to keep older or multiple versions of an application around in the Application Catalog website. The problem is when I deploy a script to remove one of these applications after removal it starts to appear under "Available
    Software" in the Software Center. Our users have noticed this and discovered that they can go there, select the application and reinstall it. I need to find a way to prevent this. Is there some sort of setting I can enable to prevent certain applications
    from showing up under "Available Software" but still have them listed in the Application Catalog Website? 

    I show in the SDK about properties passed to the Software Center that deal with Applications but nothing on how to interact with it directly in dealing with the Check box for "Show Optional Software". 
    You can always see if there is a captured regentry when you click it.  I don't know if this setting is wiped out when you close the SC.  If so you could create something to create the key to force the check box.  Sorry, maybe someone will
    have a better answer for you.
    http://www.sccm-tools.com http://sms-hints-tricks.blogspot.com
    Thanks for responding again Matthew. Yeah I googled around and got nowhere. I did find a thread here that touched on it where Torsten Meringer responded and seemed to indicate that it could not be done. I find that hard to believe (where there's a will there’s
    a way right?). I did tag the Software Center with a registry watcher on my stet VM and tried unchecking that box. Got nothing so wherever the setting resides it does not appear to be in the registry. Very frustrating to have the solution staring me right in
    the face and being unable to do anything about it. Hopefully someone who has a working method will see this thread and respond. Until then I guess I’ll keep digging.
    Side note – I’ve worked in Oil and Gas now for 10 years. Awesome to have an admin from Schlumberger respond to my post. We energy people have to stick together right? ;)

  • I am trying to download a video file which I have on my computor to facebook but Firefox continuously shows theis message"Firefox automatically prevented this page from reloading.

    Steps.
    Open Facebook page.
    On the wall select video.
    Select upload a video from your drive.and click on it.
    Drop down window opens.
    Select a video file on your computer.
    Please upload only if:
    The video is under 1,024 MB and 20 minutes.
    The video was made by you or your friends.
    Click on browse
    Firefox"File Upload window opens"Pictures Library"Exposing available videos on my file.Double click on the video selected.
    Browser window opens and shows:"Brian on the move again..MPG.
    Click on "Share"Uploading Video-Mozilla Firefox"window opens and shows: http://www.facebook.com/video/upload_popup.php?video_id=2654584286114&qn=1321170149&xhpc_composerid=uqj39y_10&xhpc_context=profile&profile_id=185862931498895
    Bellow that :Firefox prevented this page from automatically reloading."Please wait while your video uploads."But is blocked .
    Check the "Allow"button Allows it to run for about 5 seconds before blocking again. This is uploaded in the 5 second intervals 1.) 4.13 MB of 39.87 MB (13.16 KB/sec) -- 46 minutes remaining. 2.) 5.33 MB of 39.87 MB (13.22 KB/sec) -- 44 minutes remaining 3.) 6.09 MB of 39.87 MB (13.11 KB/sec) -- 43 minutes remaining. 4.) 6.67 MB of 39.87 MB (13.18 KB/sec) -- 43 minutes remaining. 5.) 6.) 7.43 MB of 39.87 MB (13.11 KB/sec) -- 42 minutes remaining etc etc and so on and so on,each time the "Allow"button is checked the message :Waiting for vupload.facebook.com -Connecting-Connected-Sending request-Transferring data appears and after checking the "Allow" button 10 or 12 times we arrive at"11.93 MB of 39.87 MB (13.22 KB/sec) -- 36 minutes remaining.The upload shows 36 minutes remaining but the video itself is no longer than 1 min 54 sec and 39.8 MB in size.

    See:
    *Firefox/Tools > Options > Advanced > General : Accessibility : [ ] "Warn me when web sites try to redirect or reload the page"
    The setting in "Tools > Options > Advanced > General" is meant as an accessibility feature, as you can see by the label of that section, so that people with disabilities or people who use screen readers do not get confused and is not meant as a safety protection to stop redirecting.
    See also:
    *https://support.mozilla.com/kb/Options+window+-+Advanced+panel#General_tab
    *http://kb.mozillazine.org/accessibility.blockautorefresh
    *http://kb.mozillazine.org/Accessibility_features_of_Firefox

Maybe you are looking for

  • Configuration documents for Training and event management &apprisals?

    hello xperts can anyone forward me configuration documents for treaining and event management and apprisal? to [email protected]

  • Two business rules runtime errors

    Hi, The business rules looks very nice but I got two runtime errors, The first I have to deploy twice else I got a wdsl error 08/02/17 13:05:16 -------> CompositeDeployerTimer: deploying composites ... 08/02/17 13:05:16 --------->deploying composite

  • MB_MIGO_BADI:Conditional New Header Tab

    Hi Experts ,   I am  writting a BADI for MIGO transaction using mb_migo_badi .I have added one new tab in PBO_Header Method .   User will input something in the field in new tab field , based on that some calculation will be there and result will be

  • IPhoto only partially updates albums after syncing

    I purchased iPhoto after I upgraded my iPad 4 to iOS 7 so I don't know if this is a new problem or not. What happens is whenever I change out albums on my PC and synch my iPad iPhoto acts very strange. It shows the new albums and new images but it tr

  • No Lights on ONT but cable boxes work (sort of)

    So beginning yesterday we have no lights on our ONT. It is plugged into the wall in a working outlet. If you wish the emergency battery button, it comes to life for about 30a seconds, we have cable again, but then poof, everything turns off again (ph