public void jButtonText_actionPerformed(ActionEvent e) { DialogText text = new DialogText(); text.setSize(500, 300); // Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = text.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } text.setLocation( (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); text.setModal(true); text.show(); server.updateGUI(); }