How To Enabling Copy and Cut Operations on Java Disabled Field










0















I'm developing a software where client request all disabled text field should be allowed to do text selection, cut and copy operations. But now unable to proceed due to some issue faced. The input field that fit the requirements should be a read-only Text Field that able to do text selection and copy/cut through ctrl+c and when clicking on the Text Field it should not trigger any Focus/Action Listener.



Previously all disabled component is disabled through




component.setEnabled(boolean)




But in this way, all disabled fields are not able to do text selection, cut and copy operations. I had tried few ways to enable copy and cut operations but found out the component is not processing any key event in this state, its seem like related to Component.enableEvents(long) I suspect this method will allow the container to dispatch the KeyEvent to the component but this method is not accessible from my project.



So I changed all the component to use




JComponent.setEditable(boolean)




But the problem with this method is, all the disabled components will trigger FocusListener, this should not happen because all the disabled fields should be read-only and have zero impact on other existing fields. Is there a way to enable the cut and copy operations without having the FocusListener to be trigger by using setEditable or there are other easier way?



(And anyone can help to explain how the event from the component is caught and dispatch? Include how the java do the checking when the keyEvent should/should not dispatch to child component and is there a way we can bypass those checking and allow the component to processKeyEvent when the field is disabled).










share|improve this question
























  • Why is the focus event a problem?

    – Maurice Perry
    Nov 12 '18 at 8:11











  • @MauricePerry, because i dont want the focus event to be trigger when user select the text for copy, some of the focus event is to perform data population/computation, but these population and computation should do only if the input field is enabled (and is huge effort to change all the focus listener to check is field isEditable before process the focusevent)

    – user9054854
    Nov 12 '18 at 8:20















0















I'm developing a software where client request all disabled text field should be allowed to do text selection, cut and copy operations. But now unable to proceed due to some issue faced. The input field that fit the requirements should be a read-only Text Field that able to do text selection and copy/cut through ctrl+c and when clicking on the Text Field it should not trigger any Focus/Action Listener.



Previously all disabled component is disabled through




component.setEnabled(boolean)




But in this way, all disabled fields are not able to do text selection, cut and copy operations. I had tried few ways to enable copy and cut operations but found out the component is not processing any key event in this state, its seem like related to Component.enableEvents(long) I suspect this method will allow the container to dispatch the KeyEvent to the component but this method is not accessible from my project.



So I changed all the component to use




JComponent.setEditable(boolean)




But the problem with this method is, all the disabled components will trigger FocusListener, this should not happen because all the disabled fields should be read-only and have zero impact on other existing fields. Is there a way to enable the cut and copy operations without having the FocusListener to be trigger by using setEditable or there are other easier way?



(And anyone can help to explain how the event from the component is caught and dispatch? Include how the java do the checking when the keyEvent should/should not dispatch to child component and is there a way we can bypass those checking and allow the component to processKeyEvent when the field is disabled).










share|improve this question
























  • Why is the focus event a problem?

    – Maurice Perry
    Nov 12 '18 at 8:11











  • @MauricePerry, because i dont want the focus event to be trigger when user select the text for copy, some of the focus event is to perform data population/computation, but these population and computation should do only if the input field is enabled (and is huge effort to change all the focus listener to check is field isEditable before process the focusevent)

    – user9054854
    Nov 12 '18 at 8:20













0












0








0


1






I'm developing a software where client request all disabled text field should be allowed to do text selection, cut and copy operations. But now unable to proceed due to some issue faced. The input field that fit the requirements should be a read-only Text Field that able to do text selection and copy/cut through ctrl+c and when clicking on the Text Field it should not trigger any Focus/Action Listener.



Previously all disabled component is disabled through




component.setEnabled(boolean)




But in this way, all disabled fields are not able to do text selection, cut and copy operations. I had tried few ways to enable copy and cut operations but found out the component is not processing any key event in this state, its seem like related to Component.enableEvents(long) I suspect this method will allow the container to dispatch the KeyEvent to the component but this method is not accessible from my project.



So I changed all the component to use




JComponent.setEditable(boolean)




But the problem with this method is, all the disabled components will trigger FocusListener, this should not happen because all the disabled fields should be read-only and have zero impact on other existing fields. Is there a way to enable the cut and copy operations without having the FocusListener to be trigger by using setEditable or there are other easier way?



(And anyone can help to explain how the event from the component is caught and dispatch? Include how the java do the checking when the keyEvent should/should not dispatch to child component and is there a way we can bypass those checking and allow the component to processKeyEvent when the field is disabled).










share|improve this question
















I'm developing a software where client request all disabled text field should be allowed to do text selection, cut and copy operations. But now unable to proceed due to some issue faced. The input field that fit the requirements should be a read-only Text Field that able to do text selection and copy/cut through ctrl+c and when clicking on the Text Field it should not trigger any Focus/Action Listener.



Previously all disabled component is disabled through




component.setEnabled(boolean)




But in this way, all disabled fields are not able to do text selection, cut and copy operations. I had tried few ways to enable copy and cut operations but found out the component is not processing any key event in this state, its seem like related to Component.enableEvents(long) I suspect this method will allow the container to dispatch the KeyEvent to the component but this method is not accessible from my project.



So I changed all the component to use




JComponent.setEditable(boolean)




But the problem with this method is, all the disabled components will trigger FocusListener, this should not happen because all the disabled fields should be read-only and have zero impact on other existing fields. Is there a way to enable the cut and copy operations without having the FocusListener to be trigger by using setEditable or there are other easier way?



(And anyone can help to explain how the event from the component is caught and dispatch? Include how the java do the checking when the keyEvent should/should not dispatch to child component and is there a way we can bypass those checking and allow the component to processKeyEvent when the field is disabled).







java swing keyevent disabled-input






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 17:32







user9054854

















asked Nov 12 '18 at 8:08









user9054854user9054854

94




94












  • Why is the focus event a problem?

    – Maurice Perry
    Nov 12 '18 at 8:11











  • @MauricePerry, because i dont want the focus event to be trigger when user select the text for copy, some of the focus event is to perform data population/computation, but these population and computation should do only if the input field is enabled (and is huge effort to change all the focus listener to check is field isEditable before process the focusevent)

    – user9054854
    Nov 12 '18 at 8:20

















  • Why is the focus event a problem?

    – Maurice Perry
    Nov 12 '18 at 8:11











  • @MauricePerry, because i dont want the focus event to be trigger when user select the text for copy, some of the focus event is to perform data population/computation, but these population and computation should do only if the input field is enabled (and is huge effort to change all the focus listener to check is field isEditable before process the focusevent)

    – user9054854
    Nov 12 '18 at 8:20
















Why is the focus event a problem?

– Maurice Perry
Nov 12 '18 at 8:11





Why is the focus event a problem?

– Maurice Perry
Nov 12 '18 at 8:11













@MauricePerry, because i dont want the focus event to be trigger when user select the text for copy, some of the focus event is to perform data population/computation, but these population and computation should do only if the input field is enabled (and is huge effort to change all the focus listener to check is field isEditable before process the focusevent)

– user9054854
Nov 12 '18 at 8:20





@MauricePerry, because i dont want the focus event to be trigger when user select the text for copy, some of the focus event is to perform data population/computation, but these population and computation should do only if the input field is enabled (and is huge effort to change all the focus listener to check is field isEditable before process the focusevent)

– user9054854
Nov 12 '18 at 8:20












1 Answer
1






active

oldest

votes


















0















but these population and computation should do only if the input field is enabled




Why is that an issue?



If you use common listener shared by all components then you just add a check to see if the component is editable.



If you use individual listeners for each component then you don't add a listener to the component if it is not editable.



I'm missing why this is a huge effort.




how the event from the component is caught and dispatch?




You might be able to use a custom KeyboardFocusManager. Maybe override the dispatchEvent(...) method to prevent the dispatching of events in your specific cases.






share|improve this answer























  • Thanks for replying my question, because the application is huge and its maintained by different developers and the listener is not a common listener different input field had a different listener and where/when the listener is added to the component also depending on the requirements. Now I'm working on the Event Queue and also EventQueueDelegate but faced some other issue. Do you have any example code or document about those java event handling?

    – user9054854
    Nov 13 '18 at 17:24











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258032%2fhow-to-enabling-copy-and-cut-operations-on-java-disabled-field%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0















but these population and computation should do only if the input field is enabled




Why is that an issue?



If you use common listener shared by all components then you just add a check to see if the component is editable.



If you use individual listeners for each component then you don't add a listener to the component if it is not editable.



I'm missing why this is a huge effort.




how the event from the component is caught and dispatch?




You might be able to use a custom KeyboardFocusManager. Maybe override the dispatchEvent(...) method to prevent the dispatching of events in your specific cases.






share|improve this answer























  • Thanks for replying my question, because the application is huge and its maintained by different developers and the listener is not a common listener different input field had a different listener and where/when the listener is added to the component also depending on the requirements. Now I'm working on the Event Queue and also EventQueueDelegate but faced some other issue. Do you have any example code or document about those java event handling?

    – user9054854
    Nov 13 '18 at 17:24
















0















but these population and computation should do only if the input field is enabled




Why is that an issue?



If you use common listener shared by all components then you just add a check to see if the component is editable.



If you use individual listeners for each component then you don't add a listener to the component if it is not editable.



I'm missing why this is a huge effort.




how the event from the component is caught and dispatch?




You might be able to use a custom KeyboardFocusManager. Maybe override the dispatchEvent(...) method to prevent the dispatching of events in your specific cases.






share|improve this answer























  • Thanks for replying my question, because the application is huge and its maintained by different developers and the listener is not a common listener different input field had a different listener and where/when the listener is added to the component also depending on the requirements. Now I'm working on the Event Queue and also EventQueueDelegate but faced some other issue. Do you have any example code or document about those java event handling?

    – user9054854
    Nov 13 '18 at 17:24














0












0








0








but these population and computation should do only if the input field is enabled




Why is that an issue?



If you use common listener shared by all components then you just add a check to see if the component is editable.



If you use individual listeners for each component then you don't add a listener to the component if it is not editable.



I'm missing why this is a huge effort.




how the event from the component is caught and dispatch?




You might be able to use a custom KeyboardFocusManager. Maybe override the dispatchEvent(...) method to prevent the dispatching of events in your specific cases.






share|improve this answer














but these population and computation should do only if the input field is enabled




Why is that an issue?



If you use common listener shared by all components then you just add a check to see if the component is editable.



If you use individual listeners for each component then you don't add a listener to the component if it is not editable.



I'm missing why this is a huge effort.




how the event from the component is caught and dispatch?




You might be able to use a custom KeyboardFocusManager. Maybe override the dispatchEvent(...) method to prevent the dispatching of events in your specific cases.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 16:25









camickrcamickr

274k15127239




274k15127239












  • Thanks for replying my question, because the application is huge and its maintained by different developers and the listener is not a common listener different input field had a different listener and where/when the listener is added to the component also depending on the requirements. Now I'm working on the Event Queue and also EventQueueDelegate but faced some other issue. Do you have any example code or document about those java event handling?

    – user9054854
    Nov 13 '18 at 17:24


















  • Thanks for replying my question, because the application is huge and its maintained by different developers and the listener is not a common listener different input field had a different listener and where/when the listener is added to the component also depending on the requirements. Now I'm working on the Event Queue and also EventQueueDelegate but faced some other issue. Do you have any example code or document about those java event handling?

    – user9054854
    Nov 13 '18 at 17:24

















Thanks for replying my question, because the application is huge and its maintained by different developers and the listener is not a common listener different input field had a different listener and where/when the listener is added to the component also depending on the requirements. Now I'm working on the Event Queue and also EventQueueDelegate but faced some other issue. Do you have any example code or document about those java event handling?

– user9054854
Nov 13 '18 at 17:24






Thanks for replying my question, because the application is huge and its maintained by different developers and the listener is not a common listener different input field had a different listener and where/when the listener is added to the component also depending on the requirements. Now I'm working on the Event Queue and also EventQueueDelegate but faced some other issue. Do you have any example code or document about those java event handling?

– user9054854
Nov 13 '18 at 17:24


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258032%2fhow-to-enabling-copy-and-cut-operations-on-java-disabled-field%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20