List of utility methods to do JDialog
void | adaptSize(JDialog frame, int preferredWidth, int preferredHeight) Set the size of the dialog to the given size, or the size of the screen if it the screen is too small. java.awt.Toolkit toolkit = frame.getToolkit(); Dimension sSize = toolkit.getScreenSize(); if (preferredWidth > 0 && preferredHeight > 0) { frame.setSize(Math.min(preferredWidth, sSize.width - 30), Math.min(preferredHeight, sSize.height - 30)); } else { frame.pack(); frame.setLocationRelativeTo(null); ... |
void | addFileOnAction(AbstractButton button, final JTextField textField, final JDialog parent) Add an action listener which presents a common file dialog. button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); File old = new File(textField.getText()); chooser.setSelectedFile(old); FileNameExtensionFilter tiff = new FileNameExtensionFilter("TIFF (large images)", "tif", "tiff"); FileNameExtensionFilter png = new FileNameExtensionFilter("PNG & JPG (regular images)", "png", ... |
void | alignDialogInMiddleOfScreen(JDialog dlg) align Dialog In Middle Of Screen Rectangle frameBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); int x = frameBounds.x + ((frameBounds.width - dlg.getSize().width) / 2); int y = frameBounds.y + ((frameBounds.height - dlg.getSize().height) / 2); dlg.setLocation(x, y); |
void | applyDefaultProperties(final JDialog comp) Sets default background and foreground color as well as a default font for the specified component. if (comp == null) { return; applyProperties(comp, "control", "controlText", null); |
Point | calculatePosition(Window parent, JDialog dialog) calculate Position int x = parent.getX() + (parent.getWidth() - dialog.getWidth()) / 2; int y = parent.getY() + (parent.getHeight() - dialog.getHeight()) / 2; Point p = new Point(x, y); return p; |
void | cascadeDialog(JDialog dialog, JDialog parent) cascade Dialog Point p = parent.getLocationOnScreen(); p.x += 20; p.y += 20; dialog.setLocation(p); |
File | chooseFile(final JDialog dialog, final String title) choose File return chooseFile(dialog, title, null);
|
void | closeDialog(final JDialog dialog) Send a WindowEvent#WINDOW_CLOSING event to the given dialog. final WindowEvent ev = new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING); dialog.dispatchEvent(ev); |
File | commonFileDialog(JDialog parent, boolean save) common File Dialog JFileChooser chooser = new JFileChooser(); if (commonFileDialogDir != null) chooser.setCurrentDirectory(commonFileDialogDir); int returnVal; if (save) returnVal = chooser.showSaveDialog(parent); else returnVal = chooser.showOpenDialog(parent); ... |
void | configureCancelForDialog(final JDialog dialog, JButton cancelButton) This method configures a standard Cancel action, bound to the ESC key, to dispose of the dialog, and sets the buttons action to be this action, and adds the action to the dialog's rootPane action map String CANCEL_ACTION_KEY = "CANCEL_ACTION_KEY"; int noModifiers = 0; KeyStroke escapeKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, noModifiers, false); InputMap inputMap = dialog.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(escapeKey, CANCEL_ACTION_KEY); Action closeAction = new AbstractAction("Cancel") { public void actionPerformed(ActionEvent arg0) { dialog.dispose(); ... |