The list of methods to do JFrame Parent are organized into topic(s).
File
AllPlatformSaveAs(Frame parentFrame, String dialogTitle, String directory, final String fileExtension, String fractionFileName, FileFilter nonMacFileFilter) All Platform Save As
File selectedFile;
if (false) {
FileDialog fd = new FileDialog(parentFrame, dialogTitle, FileDialog.SAVE);
fd.setDirectory(directory);
fd.setFilenameFilter(new FilenameFilter() {
public boolean accept(File file, String string) {
return string.toLowerCase().endsWith(fileExtension);
});
fd.setFile(fractionFileName);
fd.setAlwaysOnTop(true);
fd.setVisible(true);
if (fd.getFile() != null) {
selectedFile = new File(fd.getDirectory() + File.separator + fd.getFile());
} else {
selectedFile = null;
} else {
JFileChooser fc = new JFileChooser();
fc.setSelectedFile(new File(directory + File.separator + fractionFileName));
fc.setFileFilter(nonMacFileFilter);
fc.setDialogTitle(dialogTitle);
int result = fc.showSaveDialog(new Frame());
if (result == JFileChooser.APPROVE_OPTION) {
selectedFile = fc.getSelectedFile();
int response = 0;
if (selectedFile.exists()) {
response = JOptionPane.showConfirmDialog(null,
new String[] { "The file exists.", "Do you want to replace it?" }, "U-Pb Redux Warning",
JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (response == JOptionPane.NO_OPTION) {
selectedFile = null;
} else {
selectedFile = null;
return selectedFile;
Frame
buildParentFrame(Object inp) build Parent Frame
if (inp == null)
return null;
if (inp instanceof Frame)
return (Frame) inp;
if (inp instanceof Component) {
Component root = SwingUtilities.getRoot((Component) inp);
if (root != inp)
return buildParentFrame(root);
...
void
centreOverFrame(JInternalFrame win, JInternalFrame parent) Centre the internal frame
win over the internal frame
parent.
Rectangle parentBounds = parent.getBounds();
Dimension windowSize = win.getSize();
int x = (parentBounds.width - windowSize.width) / 2;
int y = (parentBounds.height - windowSize.height) / 2;
x = Math.max(0, x + parentBounds.x);
y = Math.max(0, y + parentBounds.y);
win.setLocation(x, y);
void
closeFrameWhenEscapePressed(final JRootPane panel, final ActionListener actListener) close Frame When Escape Pressed
@SuppressWarnings("serial")
Action escAction = new AbstractAction(ESCAPE_ACTION_NAME) {
public void actionPerformed(ActionEvent evt) {
actListener.actionPerformed(evt);
};
escAction.putValue(Action.ACTION_COMMAND_KEY, ESCAPE_ACTION_NAME);
KeyStroke escKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
...
JDialog
createExceptionDialog(Frame parent, String title, Throwable error) create Exception Dialog
ByteArrayOutputStream messageStream = new ByteArrayOutputStream();
PrintWriter out = new PrintWriter(messageStream);
error.printStackTrace(out);
out.close();
JTextField errorMsg = new JTextField(error.toString());
JTextArea errorText = new JTextArea(messageStream.toString());
JScrollPane textPane = new JScrollPane(errorText);
errorText.setEditable(false);
...
JDialog
createProgressDialog(Frame parentFrame, String title, JProgressBar progressBar) Creates the progress dialog.
JDialog dialog = new JDialog(parentFrame, true);
dialog.setContentPane(progressBar);
dialog.setTitle(title);
char c = '\u012C';
byte byte0 = 50;
int x = (parentFrame.getX() + parentFrame.getWidth() / 2) - 150;
int y = (parentFrame.getY() + parentFrame.getHeight() / 2) - 25;
dialog.setBounds(x, y, 300, 50);
...
void
enableAllComponents(final boolean enable, final Frame parent) Enables/Disables all the components of a Frame based on the input.
if (null != parent) {
Component[] components = parent.getComponents();
if (null == components) {
return;
if (components.length <= 0) {
return;
for (Component component : components) {
if (null != component) {
component.setEnabled(enable);
void
enableAllComponentsExcept(final boolean enable, final Frame parent, final Component... components) Enables/Disables all the components of a Frame except the specified components based on the input.
if (null != parent) {
Component[] allComponents = parent.getComponents();
if (null == allComponents) {
return;
if (allComponents.length <= 0) {
return;
for (Component component : allComponents) {
if (null != component && components != null) {
if (contains(component, components)) {
continue;
component.setEnabled(enable);