Highlighting problems

Hi,
i have created a specific JTextField that, among other things, only can take in numbers. To do this I have modified the Document of the textfield.
My problem is that the user can toggle between two different textfields using a combo box. One textfield of this kind and one standard JTextField. When the user toggles the focus should be on the text field, and if there is text in the textfield it should be highlighted. This works fine for the standard JTextField using requestFocus() on the textfield, and a FocusListener that does a selectAll() when the text field recieves focus. But my "enhanced" textfield gets a null pointer exception when the selectAll() occurs. Any ideas?
The TextFields new Document
protected Document createDefaultModel() {
return new FaTkTaxNrDocument();
protected class FaTkTaxNrDocument extends PlainDocument
public void insertString(int offs, String str, AttributeSet a)
throws BadLocationException
char[] source = str.toCharArray();
int size = source.length;
char[] result = new char[size];
int j = 0;
boolean dashSet = false;
// Ska endast f� plats 7 tecken
if(this.getLength() > 7) {
return;
for (int i = 0; i < result.length; i++) {
if (Character.isDigit(source)) {
result[j++] = source[i];
if (offs+i == 6) {
dashSet = true;
else if (offs == 6 && Character.isSpaceChar(source[i])) {
result[j++] = '-';
else {
// System.err.println("insertString: " + source[i]);
if(dashSet) {
super.insertString(offs, new String(result, 0, j), a);
super.insertString(offs, "-", null);
else
super.insertString(offs, new String(result, 0, j), a);
The focus listener
public class FaTkInputListener implements FocusListener
public void focusGained(FocusEvent arg0)
     selectAll();
The null pointer exception
Exception occurred during event dispatching:
java.lang.NullPointerException
     at javax.swing.plaf.basic.BasicTextUI.damageRange(Unknown Source)
     at javax.swing.plaf.basic.BasicTextUI.damageRange(Unknown Source)
     at javax.swing.text.DefaultHighlighter.addHighlight(Unknown Source)
     at javax.swing.text.DefaultCaret.moveDot(Unknown Source)
     at javax.swing.text.DefaultCaret.moveDot(Unknown Source)
     at javax.swing.text.JTextComponent.moveCaretPosition(Unknown Source)
     at javax.swing.text.JTextComponent.selectAll(Unknown Source)
     at se.rsv.fa.tk.client.view.FaTkInputField$FaTkInputListener.focusGained(FaTkInputField.java:124)
     at java.awt.AWTEventMulticaster.focusGained(Unknown Source)
     at java.awt.Component.processFocusEvent(Unknown Source)
     at javax.swing.JComponent.processFocusEvent(Unknown Source)
     at java.awt.Component.processEvent(Unknown Source)
     at java.awt.Container.processEvent(Unknown Source)
     at java.awt.Component.dispatchEventImpl(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.LightweightDispatcher.setFocusRequest(Unknown Source)
     at java.awt.Container.proxyRequestFocus(Unknown Source)
     at java.awt.Container.proxyRequestFocus(Unknown Source)
     at java.awt.Container.proxyRequestFocus(Unknown Source)
     at java.awt.Container.proxyRequestFocus(Unknown Source)
     at java.awt.Container.proxyRequestFocus(Unknown Source)
     at java.awt.Container.proxyRequestFocus(Unknown Source)
     at java.awt.Component.requestFocus(Unknown Source)
     at javax.swing.JComponent.grabFocus(Unknown Source)
     at javax.swing.JComponent.requestFocus(Unknown Source)
     at se.rsv.fa.tk.client.application.view.FaTkSearchBar.updateData(FaTkSearchBar.java:161)
     at se.rsv.fa.tk.client.control.FaTkModelListener.modelChanged(FaTkModelListener.java:54)
     at se.rsv.fa.tk.client.model.FaTkModel.fireChangedEvent(FaTkModel.java:78)
     at se.rsv.fa.tk.client.model.FaTkModel.setData(FaTkModel.java:110)
     at se.rsv.fa.tk.client.model.FaTkModel.runUpdate(FaTkModel.java:57)
     at se.rsv.fa.tk.client.view.FaTkSelectBox.fireDataEvent(FaTkSelectBox.java:89)
at se.rsv.fa.tk.client.view.FaTkSelectBox$FaTkSelectionListener.itemStateChanged(FaTkSelectBox.java:109)
     at javax.swing.JComboBox.fireItemStateChanged(Unknown Source)
     at javax.swing.JComboBox.selectedItemChanged(Unknown Source)
     at javax.swing.JComboBox.contentsChanged(Unknown Source)
     at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
     at javax.swing.DefaultComboBoxModel.setSelectedItem(Unknown Source)
     at javax.swing.JComboBox.setSelectedItem(Unknown Source)
     at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
     at javax.swing.plaf.basic.BasicComboBoxUI.selectPreviousPossibleValue(Unknown Source)
at com.sun.java.swing.plaf.windows.WindowsComboBoxUI.selectPreviousPossibleValue(Unknown Source)
     at com.sun.java.swing.plaf.windows.WindowsComboBoxUI$UpAction.actionPerformed(Unknown Source)
     at javax.swing.SwingUtilities.notifyAction(Unknown Source)
     at javax.swing.JComponent.processKeyBinding(Unknown Source)
     at javax.swing.JComponent.processKeyBindings(Unknown Source)
     at javax.swing.JComponent.processKeyEvent(Unknown Source)
     at javax.swing.JComboBox.processKeyEvent(Unknown Source)
     at java.awt.Component.processEvent(Unknown Source)
     at java.awt.Container.processEvent(Unknown Source)
     at java.awt.Component.dispatchEventImpl(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.LightweightDispatcher.processKeyEvent(Unknown Source)
     at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
     at java.awt.Container.dispatchEventImpl(Unknown Source)
     at java.awt.Window.dispatchEventImpl(Unknown Source)
     at java.awt.Component.dispatchEvent(Unknown Source)
     at java.awt.EventQueue.dispatchEvent(Unknown Source)
     at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
     at java.awt.EventDispatchThread.run(Unknown Source)

Hi everyone, I have changed nick from mbr1799 to Mr. Brodd
Ok guys, here is a program that reproduces the exception.
Copy, compile and run!
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.event.*;
import javax.swing.*;
public class ClipTest extends JFrame
implements ActionListener, KeyListener, FocusListener
JTextField tf = new JTextField(20);
JTextField tf2 = new JTextField(20);
JComboBox cb = null;
JComboBox cb2 = null;
JButton b = null;
JLabel l1 = new JLabel("Kommun");
JLabel l2 = new JLabel("Taxenhet");
Box toolBox = new Box(BoxLayout.X_AXIS);
String keys = null;
public ClipTest() {
String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
try {
UIManager.setLookAndFeel(lookAndFeel);
catch (ClassNotFoundException e) {
System.out.println("Couldn't find class for specified look and feel:" + lookAndFeel);
System.out.println("Did you include the L&F library in the class path?");
System.out.println("Using the default look and feel.");
catch (UnsupportedLookAndFeelException e) {
System.out.println("Can't use the specified look and feel ("+ lookAndFeel + ") on this platform.");
System.out.println("Using the default look and feel.");
catch (Exception e) {
System.out.println("Couldn't get specified look and feel ("+ lookAndFeel+ "), for some reason.");
System.out.println("Using the default look and feel.");
//e.printStackTrace();
init();
public static void main(String[] args) {
ClipTest ct = new ClipTest();
public void init() {
button.setBackground(Color.blue);
Box topBox = new Box(BoxLayout.Y_AXIS);
String[] listExamples = {"kommun", "taxenhet"};
cb2 = new JComboBox(listExamples);
cb2.addActionListener(this);
tf.addFocusListener(this);
tf2.addFocusListener(this);
fixBox();
this.getContentPane().add(toolBox);
this.pack();
setVisible(true);
private void fixBox()
toolBox.add(Box.createHorizontalStrut(5));
toolBox.add(cb2);
toolBox.add(Box.createHorizontalStrut(5));
toolBox.add(l1);
toolBox.add(tf);
toolBox.add(Box.createHorizontalStrut(5));
toolBox.add(l2);
toolBox.add(tf2);
l2.setVisible(false);
tf2.setVisible(false);
private void fixBoxKommun() {
l1.setVisible(true);
tf.setVisible(true);
l2.setVisible(false);
tf2.setVisible(false);
tf.requestFocus();
private void fixBoxTax() {
l1.setVisible(false);
tf.setVisible(false);
l2.setVisible(true);
tf2.setVisible(true);
tf2.requestFocus();
public void actionPerformed(ActionEvent e) {
System.out.println("Action " + e.toString());
String selected = (String)cb2.getSelectedItem();
if(selected.equals("kommun"))
fixBoxKommun();
else if(selected.equals("taxenhet"))
fixBoxTax();
else
System.out.println("Huh??");
public void keyPressed(KeyEvent ke) {
public void keyReleased(KeyEvent ke) {
public void keyTyped(KeyEvent ke) {
public void lostOwnership(Clipboard cb, Transferable tr)
public void focusGained(FocusEvent fe) {
if(tf.isVisible())
tf.selectAll();
else if(tf2.isVisible())
tf2.selectAll();
public void focusLost(FocusEvent fe) {
}

Similar Messages

  • Button Navigation & Highlight Problem

    I have I believe, a simple button highlight problem. I have a
    group of buttons I created on a page and want when button 1 is
    clicked it stays highlighted (each button is a MovieClip), and when
    another button is clicked the last one clicked gets cleared. All
    buttons have this initial AS to start:
    this.onRollOver = function(){
    this.gotoAndStop("focus"); //button changes colour
    this.onRollOut = this.onReleaseOutside = function() {
    this.gotoAndStop("no_focus"); //back to original / starting
    colour
    this.onRelease = function() { //here's where I'm stuck - keep
    the button highlighted and 'reset' the last one clicked.
    this.gotoAndStop("focus");
    this._parent.gotoAndStop("Pic2");
    this.onReleaseOutside = this.onRollOut = null;
    Any tips on how to make this work?

    For anyone able to help, I've change the script on my
    buttons: Some buttons still act funny - don't reset or only reset
    on rollOver. Any help?
    Tjisana
    stop();
    var num:Number = 3;
    //Mouse RollOver function: change colour when mouse passes
    over button
    this.onRollOver = function() {
    if(_global.link != num) {
    this.gotoAndStop("focus");
    //Mouse or Pointer Rollout & ReleaseOutslide function: go
    back to original colour
    this.onRollOut = this.onReleaseOutside = function() {
    if(_global.link != num) {
    this.gotoAndStop("no_focus");
    this.onRelease = function() {
    if(_global.link != num) {
    _global.link=num;
    for(var i=1; i<=6; i++) {
    this._parent["space" + i].gotoAndStop("1");
    this._parent["space" + _global.link].gotoAndStop("1");
    this._parent.gotoAndStop("P3"); //change to new picture
    this.gotoAndStop("focus"); //keep button highlighted
    };

  • JComboBox selection and highlight problem of the selected item

    Hi,
    I have a question how can I make my newly added item to the combo-box selectable and highlighted. I am adding new items to my custom comboBox dynamically and I want whatever item I add to be selected by default. I am using my own custom ComboBoxModel that extends AbstractListModel and implements ComboBoxModel and TreeModelListener, and my custom Renderer that extends JLabel and implements ListCellRenderer. Because I am trying to get a tree structure in my comboBox model and that's why I have my own custom model and renderer. Now when I add a new node or item to my comboBox it is being added and shown in the combo-box textField, but as soon I pull down the combo-box my parent directory is selected though my current selection is the last node added. That's how I am adding new nodes and making it selectable
    treeModel.insertNodeInto(tempNode, (DefaultMutableTreeNode)nodeCollection.lastElement(), 0);
    int nodeTotal =((CMRGlobals.myTreeGlobals).getModel()).getSize();
    Object lastNode = CMRGlobals.myTreeGlobals).getModel()).getElementAt(nodeTotal - 1);
    ((CMRGlobals.myTreeGlobals).getModel()).setSelectedItem(lastNode);
    when I do this my node is added under my parentNode and is shown in the comboBox but when I try to pull down the combo my parent node is high lighted and when I move out of the combo-box my parent node gets selected and show in the combo-box though I haven't selected it,and the contents of my last node are shown. I am just writing my own custom model that simulates the effect of JTree. I am using these......
    DefaultMutableTreeNode and
    DefaultTreeModel
    and in my JComboBox I am setting my model as
    this.setModel(new myModel(treemodel));
    this.setRenderer(new myRenderer());
    I am building my own FileDialog that just works like FileDialog I have all the functionality except this problem.Thanks for any help. I know I have posted this same thread yesterday but I didn't get any response hoping now may somebody can help me.Thanks again

    never mind I got it
    Thanks

  • Nasty highlights problem in Lightroom

    I've been a die-hard Nikon Capture user for some time but am trying out LR. On the whole I really like it and would buy it as it is likely to save me a load of time post-processing big event shoots.
    However this evening I've found a really quite nasty problem with highlight detail that is now seriously putting me off the product.
    OK, take a look at this picture. This is straight out of my D200 with no processing applied in Nikon Capture 4:
    http://www.robgillespiephoto.co.uk/piccies/fire_nc1.jpg
    This second example is the same NEF file but fed through Lightroom - all values defaulted:
    http://www.robgillespiephoto.co.uk/piccies/fire_lr1.jpg
    Notice how bad the flames look?
    OK, this one has been run through Lightroom but with the highlight recovery setting maxed out to 100:
    http://www.robgillespiephoto.co.uk/piccies/fire_lr2.jpg
    But wait, look at this 100% crop from the same processed version - notice the odd red pixels that look a bit like paint has been daubed on the photo:
    http://www.robgillespiephoto.co.uk/piccies/fire_lr3-crop.jpg
    I've tried playing with both Exposure and Recovery settings and this is as good as I can get it. I'm really disappointed that LR is not able to process this highlight detail sufficiently.

    What is the color temp you have natively there, and what is set in LR?
    You could post the RAW file for folks to take a crack at converting it to your taste. The only other one today was too cold <2000k to be properly processed. ?Er, don't think that's the problem here....

  • Yosemite Preview Highlighting Problems

    I use Preview all the time for school. It has been working fine on my iMac, but on my MacBook Air I've been having problems since the semester started up again on Monday.
    I cannot use the right click menu inside of a PDF document to highlight material on the MBA. On my iMac, this works fine in the same PDF file (Synced via Dropbox). If I select the highlight tool from the menubar, I can highlight text, but when I click on the highlighted text, I cannot change the color of the text using the right-click menu.
    I've tried restarting, clearing the com.apple.Preview files, logging in to safe mode, and creating a new user and the problem persists. Any ideas of what else I could try?

    I have the same problem in my MacBook Pro(Mid2012), after  update 10.10.2 beta 2. Right click in Preview cannot highlight PDF, while highlight using tool bar works well. This problem prevent me from using Preview in my MacBook.
    Another problem is that, after updated to Yosemite. Text inserted to pdf is not well organized. It seems that the display border of text have been changed in Preview (Yosemite). This bugs made my previous annotated pdf files look ugly, even if they are annotated by Preview (mavericks). Interestingly, these files are displayed correctly in  Goodreader, PDF Expert 5, and Dropbox.

  • Adobe reader for iPad highlighting problems

    I am unable to highlight a single column of a two column document. It results in half the page being highlighted which is not what I was trying to do. Can anyone please advise?  Thanks

    Hi Hollinst,
    Thanks a lot for your valuable suggestion.
    We have noted your request and have added it into our feature backlog. We can't say when they'll be available, but we're constantly looking to solve the problem our loyal users encounter.
    Thanks
    -Satyadev

  • RAW Highlights Problem with conversion from Canon 5D

    Hello All,
    I recently upgraded my camera from a Canon 20D to a Canon 5D. I shoot only RAW and I recently shot a couple of images of a beautiful sunset out West. I was bracketing the exposures all over the place since the light-drk contrasts were really large and the light was changing so fast. The images looked great on the Camera's LCD but, when I ran them through Aperture I got some really nasty artifacts on the conversions around the highlights. Here are examples:
    Full scene
    http://www.flickr.com/photo_zoom.gne?id=307781903&size=l
    Full scene detail:
    http://www.flickr.com/photo_zoom.gne?id=307781906&size=o
    Another example:
    http://www.flickr.com/photo_zoom.gne?id=307781905&size=l
    the problem I see is with the nasty transition from yellow to white in the blown highlight. I also don't like the broad areas of flat yellow - the tonality is completely missing. These are the default RAW settings exported to JPGs and the poor image quality of the highlights looks identical on screen between the RAW images in Aperture and these JPGs, so it's not a JPG artifact.
    I don't recall having this problem with the 20D - is the 5D conversion more difficult for Aperture? Might I be doing something wrong? Is there a way to fix this? I ran the RAW file through lightroom and it didn't have the same problem. Please help!
    -Steve G

    I have the same problems when I shot the sun rise and sun set.. It is very nasty transition from yellow to white or white to yellow from the sun. I don't think Aperture can fix that. It was over the exposure with the sun. And yes, it looks great on 2 inches LCD. I think you need to use filter when you shoot the sunset or sunrise to get the perfect lighting. Let me know, if you know the tweak with Aperture.. I will check out lightroom... I have alot of sunet and sunrise photos to correct.. and i checked out this place http://www.all-creatures.org/pics/sunset.html they have the same problems with yellow to white...

  • Code highlighting problems in CS4

    Hey guys and gals,
    I've been using dreamweaver for about a year now as a codeing enviroment for PHP web sites. The last couple of mounths a problem has started occuring randomly when I'm  working. The code highlighting starts screwing up. It does one of two things it eaither changes large chunks of the code to be colored like coments, or it all goes black like plain text. If i go to the top of the document and hit enter it changes everything back to normal for a minute or two and then the problem begins again. This obviously isn't a problem that stuns productivity but it is anoying to no end, and stunts my ability to track down mistakes like forgeting a $ .
    any one know how to fix this?
    thanks in advanced

    Hey guys and gals,
    I've been using dreamweaver for about a year now as a codeing enviroment for PHP web sites. The last couple of mounths a problem has started occuring randomly when I'm  working. The code highlighting starts screwing up. It does one of two things it eaither changes large chunks of the code to be colored like coments, or it all goes black like plain text. If i go to the top of the document and hit enter it changes everything back to normal for a minute or two and then the problem begins again. This obviously isn't a problem that stuns productivity but it is anoying to no end, and stunts my ability to track down mistakes like forgeting a $ .
    any one know how to fix this?
    thanks in advanced

  • Adobe Reader X highlighting problem

    When I highlight text in Adobe Reader X, everything works fine until i close out the document and reopen it.  Then all of the text i highlighted becomes pure yellow and completely blocks the words.  I have tried changing the opaqueness or whatever and it works until i get back into the document, and it is solid yellow again..?

    I can confirm this problem.  Rolling back to version 9.4 fixes it.
    One of my clients is a travel notary and ran into this issue today.  All print settings were set up per Adobe's instructions at http://kb2.adobe.com/cps/332/332720.html#main_Mixed_sizes when the problem occurred.  We had recently upgraded to Reader X, and had never had the probem before.  I eventually traced it to a problem in the new version.  Uninstalling and installing version 9.4 fixed the issue.  I cannot include the actual document due to privacy concerns, but I will include a screen shot that has been sanitized.

  • Highlighter problem

    I'm using Acrobat 9 pro. Sudddenly, when I highlight text in a pdf file, the text disappears and is replaced by a solid yellow bar (the highlight). Deleting the highlight returns the text. Adjusting the opacity of the highlight in "properties" doesn't fix the problem. This is peculiar to only select documents. The one in question, PDF version 1.6 created with Distiller 8.1.0. Another, PDF version 1.6 created with Distiller 7.0 has no problems. Neither has security restrictions (everything allowed).
    Any suggestions?

    The problem is a bug in Acrobat 9.0 Pro. If one PDF is opened and then a second is opened, the first may be highlighted without problem but the second will experience the problem described. If the first is then closed, the second still cannot be highlighted properly. However, if it is closed and then reopened, it will highlight correctly. You're welcome, Adobe.

  • Reader X Search highlighting problem

    I've just updated to Reader X & have discovered that the 3rd party search hit highlighting feature is no longer there. I do a lot of searching of online newspaper archives & the loss of the highlighted search term on a page is a major problem. Is there an alternative to uninstalling Reader X & reinstalling an earlier version?
    On a more philosophical point - why do software updates so often remove the most useful [to me] features?

    re: Acrobat 9.4.5
    Ruined as of June 16, 2011
    I just talked to support. They promise a fix in about a week (translation - July).
    The only workaround they offer is to uninstall & install to the last version you have on disc. Helpful, huh?
    Inundate them please: 800-642-3623 (press 2, then press 2 again for Acrobat tech support)

  • Preview Highlighting Problem

    I have been hoping there would be some sort of update to fix this problem it still has been going on ever since I have had this mac (over a month).  Whenever I highlight any text in preview it makes this weird shape with a bunch of triangles.  I really do need this to get fixed as soon as possible since I am a student.

    I find the easiest way to solve this problem is to do a print, and in the printing dialogue, export to pdf. If anyone at apple needs a document that demonstrates this problem, I could easily supply one. Seems to occur with pdf's exported from powerpoint.

  • Niggling highlighting problem.

    I am typing a document and notice in a previous sentence that punctuation or maybe a word, is wrong.
    Action ... Cursor to error > click. Intent ... Correct error using delete.
    Result ... (frequently, but NOT always)
    The styles draw icon appears (often highlighted) ... or the punctuation mark ... or the whole
    word ... or even the whole paragraph appears highlighted. And it can be a nuisance.
    I suspect that some of my keyboard/mouse settings may be wrong ... but which? Could anyone advise the settings most likely to affect highlighting in such an apparently random way.
    The problem is unique to pages; responses to websites are unaffected.

    In Pages '08, it apparently takes a double-click to highlight a word rather than just a character.
    You might look at the 'key repeat rate' and 'delay until repeat' settings for the keyboard, and the 'double-click speed' set for your mouse or trackpad, and try slowing them (drag to the left).
    If you're using any of the 'form letter' templates created by Apple, many fields are used (e.g. address book entries) , and the entire field is selected when you click anywhere in the field.

  • Listbox highlighting problem

    I am having a problem with a listbox in 7.1.1.  I have "1 item" selection mode set.  Sometimes the highlighted item in the listbox is changed manually with a mouse click, and sometimes it is changed programmatically.
    My issue is that sometimes the shading that indicates the selected item gets "stuck" on a selection, so that the previously selected item, and the new item, are both highlighted.  This happens with programmatic and manual selected item changes.  Over time, several items are highlighted.  The program corrects itself when the scrollbar of the listbox is moved.  (The programs functions properly otherwise.)
    It seems that its a labview issue, which is fine, but I will give up trying to rework my program.  Or maybe there is a workaround to prevent it.  I've tried putting some wait functions and sequence structures in different locations to give labview more time to change the highlight, but nothing seems to work.  ??
    Thanks!
    Greg
    v7.1
    Solved!
    Go to Solution.

    gstanczak wrote:
    Clever!  I will refer to you for my plumbing problems as well.
    Greg
    Now you did it! You gave me a reason to tell another Family Sea Story.
    One summer my dad was remodling one of his bathrooms and they (dad, sister and brother) had everything ripped out and had rags stuffed in the waste stack. So they worked for a while and later realized those rags are there anymore, bummer. So they broke out the snake and quickly snagged those rags BUT neglected to shut off the drill while pulling it out.
    My sister has a video of when The Sh#$ hit the fan". She still giggles ever time we talk about another remodeling project.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Text field highlight problem after caret position is set

    Hi,
    What I am trying to do is: set caret position and then highlight the text after it. The problem is: if I set caret position first, and highlight the rest of the text, the caret position is then set at the end of the entire text; if I highlight text first, and set caret position, then the text is not highlighted.
    I am wondering how I can achieve this. Thanks.
    The simple test program is below:
    import java.awt.FlowLayout;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    public class TestTextFieldHighlight {
         public static void main(String[] args) {
             JFrame f = new JFrame("Text Field Examples");
             f.getContentPane().setLayout(new FlowLayout());
             JTextField tf = new JTextField("SampleTextField", 20);
             tf.setEditable(true);
             f.getContentPane().add(tf);
             tf.setCaretPosition( 5 );
            tf.setSelectionStart( 6 );
            tf.setSelectionEnd( tf.getText().length() );
            //tf.setCaretPosition( 5 );
             f.pack();
             f.setVisible(true);
    }

          //tf.setCaretPosition( 5 );
          tf.setCaretPosition( tf.getDocument().getLength() );
          tf.moveCaretPosition(6);
          //tf.setSelectionStart( 6 );
          //tf.setSelectionEnd( tf.getText().length() );

Maybe you are looking for

  • PC for AE CS5

    Hi, I want to build a new PC and I hope you can give me some advice. I'm mainly working with After Effects, Photoshop, Illustrator and also a little C4D. I don't use a lot of video footage, my focus is more on graphics (lots of layers, camera, 3d lay

  • IPod Shuffle with iTunes on Win8 64 bit. Doesn't work for me.

    Running Win 8 64bit. iTunes initially recognizes my iPod shuffle but then it disappears. Properties say driver is up-to-date. Details say Windows is removing the device. Restarted with connected and same problem. Downloaded iTunes today - 1/5/13. Any

  • Error in invoking target ntcontab.o of makefile ../../../ins_net_client.mk

    Hi, please help me on this installation problem as i facing an error. I suppose my make.log file is the same as written on Note:234898.1. The next solution i suppose is fix and install a C++ compiler. Please help/advice/suggest me on C++ compiler. My

  • Variables in Captivate

    Hi, I'm a french developper and I want to use Captivate with flash. (I created a swfbar) 1) Can I get the name of the project with a variable ? I want to show the name of the project in the swfbar. 2) I want to stor global variables in captiate. For

  • Why Does Installing The JDK On A 64bit OS Install 3 Copys of the JRE???

    I am running Windows 7 Home Premium 64bit version. I recently installed the JDK and realized that along with it 3 copys of the JRE were installed. This is a brand new computer I am running that I just brought home a few days ago so I know there not o