Adam Smith
Adam Smith

Reputation: 79

Restrict the user to not open more than 1 jframe in java swing

I have a jtable from which I'm picking up which column the user has clicked and showing one jframe respectively

DefaultTableModel model = (DefaultTableModel)Table.getModel();
int col = Table.columnAtPoint(new Point(evt.getX(), evt.getY()));
if (col == 14)
{
  new frame2(name).setVisible(true); 
} 

name is a string which I'm passing from (current frame) frame1 to a new frame (frame2). This set up works without any problems, just that if i click twice, I see two frame2 opened. Is there a way to disable multiple openings of frame2.

Upvotes: 1

Views: 43

Answers (1)

Fullslack
Fullslack

Reputation: 300

Maybe try this:

if (!frame2(name).isVisible()) {
    new frame2(name).setVisible(true);
}

Upvotes: 1

Related Questions