List of usage examples for javax.swing JDialog setLocationRelativeTo
public void setLocationRelativeTo(Component c)
From source file:Main.java
static public JDialog addDialogWindow(Frame mainWindow, Component jpanel, String title) { JDialog dialog = new JDialog(mainWindow, title, true); dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(jpanel, BorderLayout.CENTER); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.pack();//from w ww. j av a 2 s .c o m dialog.setLocationRelativeTo(mainWindow); dialog.setSize(jpanel.getPreferredSize()); dialog.setVisible(true); return dialog; }
From source file:Main.java
static public JDialog addModelessWindow(Frame mainWindow, Component jpanel, String title) { JDialog dialog = new JDialog(mainWindow, title, true); dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(jpanel, BorderLayout.CENTER); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.pack();/*from w w w.j av a 2 s .c o m*/ dialog.setLocationRelativeTo(mainWindow); dialog.setModalityType(ModalityType.MODELESS); dialog.setSize(jpanel.getPreferredSize()); dialog.setVisible(true); return dialog; }
From source file:Main.java
/** * Displays the given file chooser. Utility method for avoiding of memory leak in JDK * 1.3 {@link javax.swing.JFileChooser#showDialog}. * * @param chooser the file chooser to display. * @param parent the parent window.//from ww w .j av a 2 s .c o m * @param approveButtonText the text for the approve button. * * @return the return code of the chooser. */ public static final int showJFileChooser(JFileChooser chooser, Component parent, String approveButtonText) { if (approveButtonText != null) { chooser.setApproveButtonText(approveButtonText); chooser.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG); } Frame frame = (parent instanceof Frame) ? (Frame) parent : (Frame) javax.swing.SwingUtilities.getAncestorOfClass(java.awt.Frame.class, parent); String title = chooser.getDialogTitle(); if (title == null) { title = chooser.getUI().getDialogTitle(chooser); } final JDialog dialog = new JDialog(frame, title, true); dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(chooser, BorderLayout.CENTER); dialog.pack(); dialog.setLocationRelativeTo(parent); chooser.rescanCurrentDirectory(); final int[] retValue = new int[] { javax.swing.JFileChooser.CANCEL_OPTION }; ActionListener l = new ActionListener() { public void actionPerformed(ActionEvent ev) { if (ev.getActionCommand() == JFileChooser.APPROVE_SELECTION) { retValue[0] = JFileChooser.APPROVE_OPTION; } dialog.setVisible(false); dialog.dispose(); } }; chooser.addActionListener(l); dialog.show(); return (retValue[0]); }
From source file:Main.java
static public JDialog addModelessWindow(Window mainWindow, Component jpanel, String title) { JDialog dialog; if (mainWindow != null) { dialog = new JDialog(mainWindow, title); } else {/* w ww . java 2s.co m*/ dialog = new JDialog(); dialog.setTitle(title); } dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(jpanel, BorderLayout.CENTER); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.pack(); dialog.setLocationRelativeTo(mainWindow); dialog.setModalityType(ModalityType.MODELESS); dialog.setSize(jpanel.getPreferredSize()); dialog.setVisible(true); return dialog; }
From source file:org.duracloud.syncui.SyncUIDriver.java
/** * Note: The embedded Jetty server setup below is based on the example configuration in the Eclipse documentation: * https://www.eclipse.org/jetty/documentation/9.4.x/embedded-examples.html#embedded-webapp-jsp */// www.j av a 2s . co m private static void launchServer(final String url, final CloseableHttpClient client) { try { final JDialog dialog = new JDialog(); dialog.setSize(new java.awt.Dimension(400, 75)); dialog.setModalityType(ModalityType.MODELESS); dialog.setTitle("DuraCloud Sync"); dialog.setLocationRelativeTo(null); JPanel panel = new JPanel(); final JLabel label = new JLabel("Loading..."); final JProgressBar progress = new JProgressBar(); progress.setStringPainted(true); panel.add(label); panel.add(progress); dialog.add(panel); dialog.setVisible(true); port = SyncUIConfig.getPort(); contextPath = SyncUIConfig.getContextPath(); Server srv = new Server(port); // Setup JMX MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer()); srv.addBean(mbContainer); ProtectionDomain protectionDomain = org.duracloud.syncui.SyncUIDriver.class.getProtectionDomain(); String warFile = protectionDomain.getCodeSource().getLocation().toExternalForm(); log.debug("warfile: {}", warFile); WebAppContext context = new WebAppContext(); context.setContextPath(contextPath); context.setWar(warFile); context.setExtractWAR(Boolean.TRUE); Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(srv); classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration"); context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$"); srv.setHandler(context); new Thread(new Runnable() { @Override public void run() { createSysTray(url, srv); while (true) { if (progress.getValue() < 100) { progress.setValue(progress.getValue() + 3); } sleep(2000); if (isAppRunning(url, client)) { break; } } progress.setValue(100); label.setText("Launching browser..."); launchBrowser(url); dialog.setVisible(false); } }).start(); srv.start(); srv.join(); } catch (Exception e) { log.error("Error launching server: " + e.getMessage(), e); } }
From source file:Main.java
/** * Displays an {@link JDialog}.//www . j ava 2 s . co m * * @param parentComponent * @param title * @return */ public static void showDialog(Component parentComponent, JComponent component, String title) { final JDialog dialog; final Window window = getWindowForComponent(parentComponent); if (window instanceof Frame) { dialog = new JDialog((Frame) window, title, true); } else { dialog = new JDialog((Dialog) window, title, true); } initDialog(dialog, component, parentComponent); dialog.setLocationRelativeTo(parentComponent); dialog.setVisible(true); }
From source file:com.limegroup.gnutella.gui.GUIUtils.java
/** * Sets the location of <tt>dialog</tt> so it appears centered regarding * the main application or centered on the screen if the main application is * not visible./* www . j a va2 s . co m*/ */ public static void centerOnScreen(JDialog dialog) { if (GUIMediator.isAppVisible()) { dialog.setLocationRelativeTo(GUIMediator.getAppFrame()); } else { dialog.setLocation(GUIMediator.getScreenCenterPoint(dialog)); } }
From source file:org.simbrain.plot.piechart.PieChartGui.java
public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equalsIgnoreCase("Add")) { this.getWorkspaceComponent().getModel().addDataSource(); } else if (e.getActionCommand().equalsIgnoreCase("dialog")) { ReflectivePropertyEditor editor = (new ReflectivePropertyEditor(getWorkspaceComponent().getModel())); JDialog dialog = editor.getDialog(); dialog.setModal(true);/*from ww w. j ava 2 s.c om*/ dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); } else if (e.getActionCommand().equalsIgnoreCase("Delete")) { this.getWorkspaceComponent().getModel().removeDataSource(); } }
From source file:org.simbrain.plot.rasterchart.RasterPlotPanel.java
/** * Show properties dialog.//from w w w. j a va 2 s. c o m */ public void showPropertiesDialog() { ReflectivePropertyEditor editor = (new ReflectivePropertyEditor(model)); JDialog dialog = editor.getDialog(); dialog.setModal(true); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); }
From source file:org.simbrain.plot.barchart.BarChartGui.java
/** @see ActionListener */ public void actionPerformed(final ActionEvent arg0) { if (arg0.getActionCommand().equalsIgnoreCase("dialog")) { ReflectivePropertyEditor editor = (new ReflectivePropertyEditor(getWorkspaceComponent().getModel())); JDialog dialog = editor.getDialog(); dialog.setModal(true);//w w w . j av a 2 s .c o m dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); } else if (arg0.getActionCommand().equalsIgnoreCase("Delete")) { this.getWorkspaceComponent().getModel().removeColumn(); } else if (arg0.getActionCommand().equalsIgnoreCase("Add")) { this.getWorkspaceComponent().getModel().addColumn(); } }