How to set JTextField to show certain map scale (e.g. 1/2000)

Hi,folks. I have a JTextField instance. How can I set the format to only allow user to only type the map scale(e.g. 1/2000). I can only use the JTextField component. Thank you in advance.

I think the regex you're looking for is"1/[1-9]\\d*"Note that in the regex you posted"1[\\]\\d*"the closing bracket is quoted by the backslash, causing the error you mentioned. Not that you needed a backslash there anyways.
You can try this, but note that since replace(...) invokes remove(...) and replace(...), pasting an apparently valid String will not succeed if the slash is part of the replacement. Also that setText or pasting are the only ways to set the initial content as you won't be able to type it in one character at a time.import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
public class ScaleFactorTextField {
   public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
         @Override
         public void run() {
            new ScaleFactorTextField().makeUI();
   public void makeUI() {
      JTextField textField = new JTextField(10);
      textField.setDocument(new PlainDocument() {
         final Pattern p = Pattern.compile("1/[1-9]\\d*");
         @Override
         public void insertString(int offs, String str, AttributeSet a)
               throws BadLocationException {
            String newText = getText(0, offs) + str +
                  getText(offs, getLength() - offs);
            if (isValidText(newText)) {
               super.insertString(offs, str, a);
         @Override
         public void remove(int offs, int len) throws BadLocationException {
            String newText = getText(0, offs) +
                  getText(offs + len, getLength() - offs - len);
            if (isValidText(newText)) {
               super.remove(offs, len);
         @Override
         public void replace(int offs, int len, String text,
               AttributeSet attrs) throws BadLocationException {
            String newText = getText(0, offs) + text +
                  getText(offs + len, getLength() - offs - len);
            if (isValidText(newText)) {
               super.replace(offs, len, text, attrs);
         private boolean isValidText(String text) {
            Matcher m = p.matcher(text);
            return m.matches();
      textField.setText("1/20000");
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.add(textField);
      frame.pack();
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
}db

Similar Messages

  • How to Set JFilechooser to show file with the same extension in the filetyp

    How to Set JFilechooser to show file with the same extension in the filetypes??
    help

    I also don't understand, but if you mean how to display only files with a certain extension in your JFileChooser then you should have a look at the JFileChooser API:
    http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JFileChooser.html
    The introduction shows an example of how to do that.

  • How to set EXPORT parameter from message mapping

    Again, ask the question of export parameter.
    I wrote a java version transformation and it worked good with export parameter.
    However I can not work it out in graphical message mapping. I refered http://help.sap.com/saphelp_nwpi71/helpdata/en/43/c3e1fa6c31599ee10000000a1553f6/frameset.htm.
    In PI7.1, I add an export parameter "EXPORT_PARA" in the "Signature" tab. Are there any special step to assign this parameter to an UDF? I did not find a way to do it.
    And then I define an UDF,
    public String SetExportPara(String sss, Container container) throws StreamTransformationException{
    String str = "GOOD";
    GlobalContainer gc = container.getGlobalContainer();
    OutputParameters paras= gc.getOutputParameters();
    if(paras.exists("EXPORT_PARA ") == true) {
    paras.setString("EXPORT_PARA ", str);
    }else {
    str = "NOT FOUND EXPORT_PARA";
    return str;
    And I assign this UDF to one element of my output XML, I tried to run it in IE, it always output "NOT FOUND EXPORT_PARA.
    why?????
    I know there is a blog : https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/8654. [original link is broken] [original link is broken] [original link is broken]
    But it did not talk how to set export parameters.

    Hi,
    i read thread
    How to export parameters from Message Mapping
    and blog
    /people/jin.shin/blog/2008/02/14/sap-pi-71-mapping-enhancements-series-parameterized-message-mappings
    but not found issue
    in this topic
    http://help.sap.com/saphelp_nwpi71/helpdata/en/43/c3e1fa6c31599ee10000000a1553f6/frameset.htm.
    if i writting this code in UDF, i getting an error.
    If use this code:
    GlobalContainer gc = container.getGlobalContainer();
    OutputParameters paras= gc.getOutputParameters();
    paras.setString("EXPORT_PARA ", str);
    the export parameter is defined locally (in transformation step area). In integration process area parameter is equal to NULL.
    How send export parameter to Integration Process? For exapmple, i wanna send parameter to other transformation step in my integration process.
    thx.

  • How to set public even show detail to to all users

    How to set public even to show detail to all users or group. By default the public event only show "Busy" on calendar.

    Change the calendar's "everybody" permissions to include "Read" permisssion

  • How to set preference to "show all" open windows in all open applications (until I quit)

    how do I set preferences to "show all" windows in all open applications (until I quit the application) ?

    Can you explain more what the problem is and what you want to see.
    All windows are shown by default, unless you minimize them, so I'm confused at what you are asking.

  • How to set Photoshop to show actual print size?

    When I go to View Print Size the resultant image is smaller than the actual print size.  How do I set PS to show the actual size on my monitor?

    Measure the physical horizontal viewing length of your monitor. 11.25 inches for example.
    Then the horizontal resolution your monitor is set to. 1280 pixels as an example.  divide 1280 by 11.25 to get 113.77 pixels per inch, your screen resolution. Round it out to 114.
    In Photoshop: Edit menu > Preferences > Units and Rulers, and in New Document Presets, change the Screen Resolution to 114.  Click OK, restart Photoshop.
    After that when you use View > Print Size, your onscreen rulers will match up to a physical ruler and your documents will be at the physical print size set in your document's dimensions under Image > Image Size.
    Gene

  • How to set a pixel to certain value in a Graphic object.

    Hello Every One
    I want to set a certain point in a graphic context to a new Color value let say i have a point (x, y)=(100, 100)
    and i have a JFrame window i can do like this
    Graphics g = getGraphics();
    Now i want to set the point(100, 100) to a new Color say red.
    Please tell me how to do that.
    Thanx Alot

    I was wondering about this earlier today too...
    you can use Graphics.drawLine with the startpoint and the endpoint equal to draw a dot on that pixel, but this seems like overkill.
    /me joins csquadian waiting for an better answer

  • How to set windows at a certain size in Lion ?

      Hi Guys
      this is something i have been having an uphill struggle trying to get right - to say the least !!..
      in Snow Leopard one could only ''resize'' a window by pulling on it's corners ( NOT a limitation in my book.. )  but when you closed the window & later opened it again, it remained the size it was when you last closed it
      now with Lion one can ''resize'' the windows by pulling anywhere ( just like Windows - HURRAY !?.. ) BUT when you close it & open it again later, Lion resizes it forcing me to - AGAIN.. - size it back to my preferences/needs and to me THAT my friends IS a SERIOUS limitation to my efficiency
    on my 27'' iMac i like my windows to be roughly  8'' tall X 10'' wide, that combined with my file & folder's size gives me a nice working space, showing most of that window's content WITHOUT scrolling, etc.... MOST IS clearly displayed to see, what could be easier than that ?
    the PROBLEM is that this happens 10, 15 or even 20 times a day, WASTING my time & effort in the process - for NOTHING !!
    & that's what drives me nuts : constantly resizing windows ? in my neck of the woods there ARE better things to do.....you know what i mean ? this IS MOST frustrating given the pointlessness of the effort wasted
    what can i say ? i'm a lazy bugger who doesn't enjoy repeating the same task  OVER & OVER again - anyone has a suggestion on how to avoid this ?
    i'd truly appreciate a solution for this
    many thanks

    Hello Pankaj
    You will find a solution for your problem in sample report <b>BCALV_EDIT_03</b>. If you do the error handling in the event handler method for DATA_CHANGED then the cursor will point to the field containing the faulty value.
    Here is part of the report's header documentation:
    program bcalv_edit_03.
    * Purpose:
    * ~~~~~~~~
    * In this example the user may change values of fields
    * SEATSOCC (occupied seats) and/or PLANETYPE. The report checks
    * the input value(s) semantically and provides protocol
    * messages in case of error.
    * To check program behavior
    * ~~~~~~~~~~~~~~~~~~~~~~~~~
    * Change values of the column "occupied seats" or "Planetype" or
    * both (in the same line). Try to provocate errors.
    * Click on the check symbol or press return to initiate checking.
    * (ALV also checks input before any functions like sorting,
    * filtering or doubleclick are processed. These functions are
    * only active if the input does not contain any errors).
    * The ALV Grid Control first checks if the input is correct
    * according to DDIC-Information (Type, lenght). Then semantic
    * checks are made by the application using event handler method
    * HANDLE_DATA_CHANGED.
    Regards
      Uwe

  • How to set the color for road map steps

    hi all,
    my requirement is like ,whenever i select my step in a roadmap it has to be set in yellow color and others has to be in default color.
    thanks,
    Siva.

    Hi......
    Its Very Simple......
    Create an action for the road map.
    for example..... if you have three step in it....
    by default the first step will be in active only...
    ie., Yellow colour
    if you click the second step and it should be active means.... if you have to create a event....in the property of the Roadmap
    Create the on action select event....
    in that event.....
    try to use this code.... based on your scenario.....
    set context data
        DATA: road_node TYPE REF TO if_wd_context_node,
              road_data TYPE if_componentcontroller=>element_roadmap.
        road_node = wd_context->get_child_node( 'ROADMAP' ).
        road_data-step = step.
        IF step = 'CHOOSE'.
          road_data-prev_enabled = abap_false.
        ELSE.
          road_data-prev_enabled = abap_true.
        ENDIF.
        IF step = 'END'.
          road_data-next_enabled = abap_false.
        ELSE.
          road_data-next_enabled = abap_true.
        ENDIF.
        road_node->set_static_attributes( road_data ).
    navigation
        wd_this->fire_navigate_evt( step ).
    Hope this will help you
    Thanks & reagrds
    Raja

  • How to set default TV show cover in iTunes 11?

    Hi to all!
    I have just updated to the new iTunes 11 and I am going through all the changes and the new features. My first to question to anyone who has ansewrs is this:
    As I saw in the TV Shows section they have finaly gathered all the seasons into each tv show title, so now we don't have three "Boardwalk Empire" (one for each of the three seasons) for example but one where you get to click and see all the episodes and seasons inside Right?
    How do you get to change the cover of each series thought? For example in some shows I get the cover of the first season and in others the last. Is there a pattern or is it random? And if not is there a way that I choose which season cover represents the series?
    Thanks for your time!

    Still nothing too… Can anyone at least menion what was updated in 11.0.1?
    I don't know what to say Totux. Is it just me or Apple is heading back to the stone days of the 90s? I mean seriously what did these guys do in the last year? A new port for iPhone, two beta OSs and a lot of bad software.
    This is supposed to be the "easiest iTunes ever" and I haven't met anyone liking it yet. I suppose we will have to start thinking everything is a "feature" from now on

  • How to set Canvas to show actual playback area size

    I have sequences that have source video footage in different aspect ratios (from VHS, Mini-DV etc.), however in FCE Easy Setup I have the output set to NTSC 720x480. Some of the sequences have video footage solely from the Mini-DV that is in a wide screen format (I believe 16:9), however that exact ratio is not important to this question.
    Question: I need to re-scale and pan the Mini-DV video so as to better relate to the output 720x480 format. Currently in either the Canvas or Viewer only the fully wide screen Mini-DV view is displayed. Is there a way to also display the 720x480 output window so as to be able to position the wider and shorter Mini-DV video?

    Thanks Skalicki that works. I am confused on one item though. I had initially created a sequence with the Mini-DV video inserted where the Canvas and Viewer only showed the widened view (not overlaid with the 720x480 output limits showing). I followed your advise then copy/pasted the same footage into the newly created sequence and I now get the correct width video with bars at top and bottom that I can easily correct using the Motion settings. Do you know why the initial sequence would not include the 720x480 output? Thanks for any thoughts.

  • How to set JTextField length?

    pnlBkBorrow = new JLabel("Book borrowed");
    pnlMain.add(pnlBkBorrow);
    textBkBorrow = new JTextField(25);
    pnlMain.add(textBkBorrow);I am using GridBagLayout, but the length is only 1 after compling

    I'm not a swing expert (and never used GridBagLayout, actually) but as far as I know, you must use GridbagConstraints to do what you asked.
    Look at this example with a JButton:
    JButton button;
    pane.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    button = new JButton("Button 1");
    c.weightx = 0.5;
    c.gridx = 0;
    c.gridy = 0;
    pane.add(button, c);
    button = new JButton("Button 2");
    c.gridx = 1;
    c.gridy = 0;
    pane.add(button, c);
    button = new JButton("Button 3");
    c.gridx = 2;
    c.gridy = 0;
    pane.add(button, c);
    button = new JButton("Long-Named Button 4");
    c.ipady = 40;      //make this component tall
    c.weightx = 0.0;
    c.gridwidth = 3;
    c.gridx = 0;
    c.gridy = 1;
    pane.add(button, c);
    button = new JButton("5");
    c.ipady = 0;       //reset to default
    c.weighty = 1.0;   //request any extra vertical space
    c.anchor = GridBagConstraints.PAGE_END; //bottom of space
    c.insets = new Insets(10,0,0,0);  //top padding
    c.gridx = 1;       //aligned with button 2
    c.gridwidth = 2;   //2 columns wide
    c.gridy = 2;       //third row
    pane.add(button, c);and the result should be like this http://java.sun.com/docs/books/tutorialJWS/uiswing/layout/example-1dot4/GridBagLayoutDemo.jnlp

  • Cannot get slide show in full screen mode to come up on secondary monitor regardless of how I set up show it always opens on primary screen.  Need some help here.

    Slide show in PowerPosint for mac 2011 on iMac will not open full screen mode on secondary monitor.  Regardless of how I set the slide show preferences it always opens on primary monior with secondardy monitor having totally balck screen.  Need some help if anyone else has run into this problem.

    You should contact Microsoft for Mac Support  and/or post in their forums.

  • Setting a TV show as seen

    I can see how to set my music as being played and my podcast as being played, but I can't see how to set the TV shows as being played. this has become a problem because I recently had to rebuild my hard disk and thus reimport all the music. When I did that, everything came back in as unplayed. I need to find a way to mark all the shows that I have seen as played so that my iPod does not load everyone of the shows.
    thanks,

    control click is the same as a right click.
    Or go to System prefs -> Keyboard and Mouse -> Trackpad and enable *Tap trackpad using two fingers for secondary click*.

  • CWgraph - how to set db in Y-Axes

    Hi,
    I would like to use the CWGraph component to display the frequency domain of a signal.    Please see the attached photo for the desired result.
    I couldn't find how to set the Y-axes to db scale.
    Please help
    Thanks
    Rafi
    Attachments:
    Freq domain.gif ‏21 KB

    Hi Eric and thanks for your response
    1. I am looking to do the frequency response
    2. I do have the enterprise edition which also include LabView and CVI
    3. I'm working on a project which is written in VB6 and that is why I prefer to use the measurement studio to perform the signal analysis.  I know that I can do the analysis in LabView and call it from VB.  I will check that option only if I won't be able to accomplish the task with the measurement studio.  What do you think?  (see the list of task I need to deal with)
    4. My project requires reading data (could be hundreds thousands of points) and then, displaying:  
                Time domain
                frequency domain
                frequency response 
                histogram
                Pulse response
        Also calculating:
                SNR
                Linearity
                rms
                p-p
    Any advice would be greatly appreciated
    Rafi

Maybe you are looking for