Maximilian
Lifer
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:
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:
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?
I decided to implement a copy/paste function for it:
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?