• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Bit of a niggle with Swing text input

 
Ranch Hand
Posts: 342
1
Mac Eclipse IDE Safari
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I appreciate Swing applications are not as main stream as they once were - but I'm still creating them.

I have one niggle which I've had since "for ever" which maybe someone has worked around.

Lets say you have a frame which has a text input field on it with some text populated and you want to replace it with something else.

Now you can place the cursor at the end of the existing text and click backspace to remove it one character at a time,

or you can do what I prefer which is to use the mouse to highlight all of the text and then click backspace just once.

The problem is that if you use the second approach and then start typing then you end up with a single character which appears to be highlighted and gets overtyped each time you type a letter.

Kinda annoying

Is there a cunning way to prevent this behavoir - if I've removed all of the text then I should be able to just resume typing without this (I don't know what to call it) odd behavior.

I have other apps which I am not the author of which do the same - so it's not my Java code which is causing it.

Some peculiarity of Java Swing

Dave
 
Sheriff
Posts: 22841
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use Ctrl+A to select all text instead of using the mouse. You can then also use delete, it will work the same as backspace.

I've tried your way (select all with the mouse, backspace, then start typing) but there's no highlight (both Java 11 and Java 23 on Windows). What Java and OS are you using?
 
Saloon Keeper
Posts: 28599
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I usually do a "select all" on the text in that field when it gains focus. Been doing that since long before there was a Java, much less a Swing.

Most of the time, that is what I want. To completely replace the entire field. And if it isn't, I just de-select the text and cursor to where I want to change it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic