By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,738 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,738 IT Pros & Developers. It's quick & easy.

Using Copy (Ctrl-C) functionality with disabled JTextFields

P: n/a
I am working on a Swing application (Java 1.4 ) and I am having
trouble implementing the following functionality:
A JTextField that should not be part of focus traversal (should
not be tabbed to), but the text can be selected and copied (Ctrl-C).

This is a requirement across the whole application, which is
hundreds of panels, so 'hard-coding' the tab order is not an option.

TIA,
John
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
JMBollard wrote:
I am working on a Swing application (Java 1.4 ) and I am having
trouble implementing the following functionality:
A JTextField that should not be part of focus traversal (should
not be tabbed to), but the text can be selected and copied (Ctrl-C).


Okay -- first off, Ctrl-C isn't Copy on every platform. Many use
Shift-Insert instead. So if you're coding a platform-neutral
application, don't hard-code Ctrl-C -- let the OS take care of it.

As to your specific issue, if you don't want to simply remove the
JTextField from the tab order, why not just disable it (as I'm assuming
you want to do) and then put a "Copy" button beside it that will take
its output and send it to the clipboard through the proper Transferrable
object? Seems to be the easiest way to me.

Brad BARCLAY

--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project: http://www.jsyncmanager.org

Jul 17 '05 #2

P: n/a
JMBollard wrote:
I am working on a Swing application (Java 1.4 ) and I am having
trouble implementing the following functionality:
A JTextField that should not be part of focus traversal (should
not be tabbed to), but the text can be selected and copied (Ctrl-C).

This is a requirement across the whole application, which is
hundreds of panels, so 'hard-coding' the tab order is not an option.

I believe the best way to accomplish this is with the
Component.setFocusTraversalPolicy() method. You could pass it a
subclass of ContainerOrderFocusTraversalPolicy with an accept() method
that rejects all JTextFields.

HTH,
Ray

Jul 17 '05 #3

P: n/a
Thanks for the response.

Sorry, I did not do a very good job of giving a detailed description
of the
issue. First, you are correct, and I am not trying to code
specifically to
Ctrl-C, I am letting the platform take care of that work for me.
Secondly,
I was considering an approach similar to the one you suggest. I was
thinking
about putting a right-click popup-menu on my 'extension' of
JTextFields with a
copy choice. The button that you mention is not very feasible in my
case,
since it involves hundreds of different screens, several which are
already
'tight' on space, but it's along the same line.

Let me try and give a better description of the problem.

The Textfield may or may not be disabled based on other fields on the
screen.
So, if Field A is X, then Field B should be non-editable, and not in
the tab
order, but I still may want to be able to 'copy' the data in Field
B.
If Field A is Y, then Field B should be editable, and should be in the
tab
order.

So, the problem is making a field non-traversable with tabbing, but
still
selectable with the mouse.

If a textfield is disabled, you cannot select the text.
If it is enabled but not editable, you can select the text, but it
also is
included in the tab order.

I am having trouble finding a combination of editable, enabled,
focusTraversable, ... that gives me the functionality I am looking
for.
Brad BARCLAY <bb******@jsyncmanager.org> wrote in message news:<iH******************@twister01.bloor.is.net. cable.rogers.com>...
JMBollard wrote:
I am working on a Swing application (Java 1.4 ) and I am having
trouble implementing the following functionality:
A JTextField that should not be part of focus traversal (should
not be tabbed to), but the text can be selected and copied (Ctrl-C).


Okay -- first off, Ctrl-C isn't Copy on every platform. Many use
Shift-Insert instead. So if you're coding a platform-neutral
application, don't hard-code Ctrl-C -- let the OS take care of it.

As to your specific issue, if you don't want to simply remove the
JTextField from the tab order, why not just disable it (as I'm assuming
you want to do) and then put a "Copy" button beside it that will take
its output and send it to the clipboard through the proper Transferrable
object? Seems to be the easiest way to me.

Brad BARCLAY

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.