473,796 Members | 2,520 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Copy (Ctrl-C) functionality with disabled JTextFields

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
3 7104
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
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.setFo cusTraversalPol icy() method. You could pass it a
subclass of ContainerOrderF ocusTraversalPo licy with an accept() method
that rejects all JTextFields.

HTH,
Ray

Jul 17 '05 #3
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,
focusTraversabl e, ... that gives me the functionality I am looking
for.
Brad BARCLAY <bb******@jsync manager.org> wrote in message news:<iH******* ***********@twi ster01.bloor.is .net.cable.roge rs.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2310
by: Tony Johansson | last post by:
Hello experts! I have this piece of code. No user defined copy constructor exist. AccountForStudent create(long number) { AccountForStudent local(number, 0.0); return local; } int main() {
3
2192
by: Johnny | last post by:
Hi, I have created an ASP.NET application (let's call it FooBar) with VS.NET on my local machine, residing in http://localhost/FooBar. Deploying it to another folder on my machine works well with FrontPage Server Extensions, but I don't manage to deploy the application to my web provider http root folder. When I run Copy Project, I get an error message just saying 'Unable to create Web project 'myname'. Not found.'.
2
29141
by: Jim S | last post by:
I am having a problem finding information regarding vb.net allowing you to create shortcut keys for buttons using the CTRL key + function buttons such as F1, F2 etc.. (Ex: Press CTRL+F1 to activate a click event on a button). If anyone could help it would be sincerely appreciated. Thank You!
0
1036
by: Graeme M via DotNetMonster.com | last post by:
Hi, I'm using visual basic.net 2003 and in two separate projects now i have encountered a frustrating issue where all context menu functionality (copy, paste, delete etc) is disabled on a TabControl in a windows form. I have scoured the internet searching for a solution, and have noted several similar posts but no real solution to the problem. Has anyone encountered this before and figured out how to fix it? or is there a fix that i need...
2
428
by: Pascal Polleunus | last post by:
Hi, I need to synchronize some tables from a database (master) to another one (slave). Both servers are running Debian Woody with PostgreSQL 7.2.1 (postgresql 7.2.1-2woody4). The databases are in unicode and doesn't contain any binary data. The tables have primary/foreign key constraints, sequences and indexes, but no triggers/rules. There are OIDs but these are different on the 2 databases. In fact they are not used by the application.
2
4467
by: al_johnson222 | last post by:
>From any page, I want to be able to call a JS function that will do the equivelant of select all, and copy. This data will then be posted to a page that will log it. This would be easy using copy/paste functionality but I don't want to screw-up users copy/paste buffer. Anyone have an example of how to retrieve all text with similar formatting of copying page to notepad without using copy/paste functionality? Thanks in advance. Al
7
1772
by: Jeffrey Barish | last post by:
(Pdb) myclass MyClass( 0, 0, 'A string', 123.45) (Pdb) copy.copy(myclass) *** TypeError: TypeError('__new__() takes at least 4 arguments (2 given)',) I see 4 arguments (actually, 5 because Python is passing cls invisibly to __new__). Does anyone have an idea what is going on here? I have not defined __new__ in MyClass above. I can make the problem go away on one platform by defining __new__ as
11
2292
by: Dijkstra | last post by:
Hi folks! First, this is the code I'm using to expose the problem: ------------------------------------------------------------------ #include <functional> #include <string> #include <iostream> using namespace std;
1
114837
by: kallem | last post by:
Hi I have one text file generated using SQLServer 2005. While I am importing the text file into one of my PostgreSQL table using "copy" it is giving me the following error: ERROR: invalid byte sequence for encoding "UTF8": 0xff Can any one tell me what i need to do get the data from SQLServer 2005 to PostgreSQL?
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10012
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.