List of usage examples for javax.swing JDialog setComponentOrientation
public void setComponentOrientation(ComponentOrientation o)
From source file:Main.java
/** * Initialises the {@link JDialog} for the {@link JComponent}. * //from w w w . j a v a2s . c om * @param dialog * @param component * @param parentComponent */ private static void initDialog(final JDialog dialog, final JComponent component, final Component parentComponent) { dialog.setResizable(true); dialog.setComponentOrientation(component.getComponentOrientation()); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(component, BorderLayout.CENTER); final int buttonWidth = 75; final JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(2, 4, 4, 4)); buttonPanel.add(Box.createHorizontalGlue()); @SuppressWarnings("serial") final Action closeAction = new AbstractAction("Close") { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; final JButton button = new JButton(closeAction); fixWidth(button, buttonWidth); buttonPanel.add(button); contentPane.add(buttonPanel, BorderLayout.SOUTH); if (JDialog.isDefaultLookAndFeelDecorated()) { boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations(); if (supportsWindowDecorations) { dialog.setUndecorated(true); component.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); } } dialog.pack(); dialog.setLocationRelativeTo(parentComponent); WindowAdapter adapter = new WindowAdapter() { // private boolean gotFocus = false; public void windowClosing(WindowEvent we) { fireAction(we.getSource(), closeAction, "close"); } }; dialog.addWindowListener(adapter); dialog.addWindowFocusListener(adapter); }
From source file:net.mariottini.swing.JFontChooser.java
/** * Show a "Choose Font" dialog with the specified title and modality. * /*from www . j av a2s. com*/ * @param parent * the parent component, or null to use a default root frame as parent. * @param title * the title for the dialog. * @param modal * true to show a modal dialog, false to show a non-modal dialog (in this case the * function will return immediately after making visible the dialog). * @return <code>APPROVE_OPTION</code> if the user chose a font, <code>CANCEL_OPTION</code> if the * user canceled the operation. <code>CANCEL_OPTION</code> is always returned for a * non-modal dialog, use an ActionListener to be notified when the user approves/cancels * the dialog. * @see #APPROVE_OPTION * @see #CANCEL_OPTION * @see #addActionListener */ public int showDialog(Component parent, String title, boolean modal) { final int[] result = new int[] { CANCEL_OPTION }; while (parent != null && !(parent instanceof Window)) { parent = parent.getParent(); } final JDialog d; if (parent instanceof Frame) { d = new JDialog((Frame) parent, title, modal); } else if (parent instanceof Dialog) { d = new JDialog((Dialog) parent, title, modal); } else { d = new JDialog(); d.setTitle(title); d.setModal(modal); } final ActionListener[] listener = new ActionListener[1]; listener[0] = new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals(APPROVE_SELECTION)) { result[0] = APPROVE_OPTION; } removeActionListener(listener[0]); d.setContentPane(new JPanel()); d.setVisible(false); d.dispose(); } }; addActionListener(listener[0]); d.setComponentOrientation(getComponentOrientation()); d.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); d.getContentPane().add(this, BorderLayout.CENTER); d.pack(); d.setLocationRelativeTo(parent); d.setVisible(true); return result[0]; }