I would like to use setAlwaysOnTop(boolean) in java.
I want to setAlwaysOnTop() when I click on a JButton and this JButton has its own actionListener
My Problem is I don’t know how to set the JFrame on top at this situation, because it’s not inside the constructor nor there is a method getFrame()
I tried creating a method inside the constructor but it does not work :S.
UPDATE:
private class optionAction implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource() == onTop) //onTop is a menuItem when I click it it should make the frame Always on top.
frame.setAlwaysOnTop(true); //This does not work of course just to demonstrat you what I want to do
}
}
The correct working code for this question is below:
The reason this is does not work because I was setting the
setAlwaysOnTopon aJFrameobject, which it doesn’t exists in that class.To set the
setALwaysOnTopon aJFrameyou have to remove theframe.and just add `setAlwaysOnTop()