• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java copy/paste popup menu...

Ive made a few applications before but ive just made my first application that's actually useful to me. Its pretty simple it just tells me the next bin collection day :biggrin:

I decided to implement a copy/paste function for it:
ge6alIg.png


Now I want it to be able to copy text from that main JTextPane and the two JLabels at the bottom. This is the code I used to do this:
Code:
class RightClickListener implements ActionListener
    {
        @Override
        public void actionPerformed(ActionEvent ae) 
        {
            if (ae.getSource() == menuItem)
            {
                String selectedText = "";
                selectedText = nextBinDayjTextPane.getSelectedText();
                
                if (selectedText == "")
                {
                    selectedText = previousBinDayjTextField.getSelectedText();
                }
                
                if (selectedText == "")
                {
                    selectedText = firstBinDayjTextField.getSelectedText();
                }
                
                StringSelection stringSelection = new StringSelection (selectedText);
                clipBoard.setContents(stringSelection, null);
                selectedText = "";
            }  
        }
    }

So basically if the selectedText String is empty it will check the next control for selected text. Is this the best way of going about it? Is there no way to check which control was actually right clicked on?
 
Back
Top