List of usage examples for javax.swing JDialog setSize
public void setSize(int width, int height)
The width and height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize .
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JDialog dialog = new JDialog(frame, false); dialog.setSize(200, 50); frame.addComponentListener(new ComponentAdapter() { Point lastLocation;// ww w . j av a 2s . c o m @Override public void componentMoved(ComponentEvent e) { if (lastLocation == null && frame.isVisible()) { lastLocation = frame.getLocation(); } else { Point newLocation = frame.getLocation(); int dx = newLocation.x - lastLocation.x; int dy = newLocation.y - lastLocation.y; dialog.setLocation(dialog.getX() + dx, dialog.getY() + dy); lastLocation = newLocation; } } }); frame.setSize(400, 200); frame.setVisible(true); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { int result = JOptionPane.showConfirmDialog(null, "Show over parent?"); for (int i = 1; i < 4; i++) { JFrame f = new JFrame("Frame " + i); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Component parent = (JOptionPane.OK_OPTION == result ? f : null); f.setSize(400, 300);/*ww w . ja v a2 s .c om*/ f.setLocationByPlatform(true); f.setVisible(true); JDialog d = new JDialog(f); d.setTitle("Dialog " + i); d.setSize(300, 200); d.setLocationRelativeTo(parent); d.setVisible(true); } }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(new Dimension(500, 500)); JDialog dialog = new JDialog(frame, "Export", ModalityType.MODELESS); dialog.setSize(300, 300); JDialog dialog1 = new JDialog(dialog, "Export", ModalityType.APPLICATION_MODAL); dialog1.setSize(200, 200);// w ww. j ava 2 s.co m frame.add(new JButton(new AbstractAction("Dialog") { @Override public void actionPerformed(ActionEvent e) { frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); dialog.setVisible(true); dialog1.setVisible(true); } })); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout(2, 3)); JPanel buttonConstrsint = new JPanel(new FlowLayout(FlowLayout.CENTER)); JButton getQuotesButton = new JButton("Load"); buttonConstrsint.add(getQuotesButton); gui.add(buttonConstrsint, BorderLayout.NORTH); getQuotesButton.addActionListener(e -> { String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" }; Object[][] data = { { "A", "B", "Snowboarding", new Integer(5), new Boolean(false) }, { "C", "D", "Pool", new Integer(10), new Boolean(false) } }; JTable table = new JTable(data, columnNames); JScrollPane scrollPane = new JScrollPane(table); table.setFillsViewportHeight(true); gui.add(scrollPane, BorderLayout.CENTER); gui.revalidate();/* w ww . j av a 2 s.c om*/ gui.repaint(); }); JOptionPane jOptionPane = new JOptionPane(gui); JDialog dialog = jOptionPane.createDialog(new JFrame(), "title"); dialog.setSize(200, 200); dialog.setVisible(true); }
From source file:com.ohalo.cn.awt.JFreeChartTest.java
public static void main(String[] args) throws Exception { JFreeChartTest test = new JFreeChartTest(); List<JFreeChart> charts = test.printHardDiskCharts(); JPanel mainPanel = new JPanel(); JFreeChart chart = charts.get(0);/*from w ww. j av a 2 s. com*/ JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(400, 300)); panel.add(chartPanel, BorderLayout.CENTER); mainPanel.add(panel, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(20, 20, 10, 10), 0, 0)); chart = charts.get(1); panel = new JPanel(); ChartPanel chartPanel2 = new ChartPanel(chart); chartPanel2.setPreferredSize(new Dimension(400, 300)); panel.setLayout(new BorderLayout()); panel.add(chartPanel2, BorderLayout.CENTER); mainPanel.add(panel, new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0)); chart = charts.get(2); panel = new JPanel(); ChartPanel chartPanel3 = new ChartPanel(chart); chartPanel3.setPreferredSize(new Dimension(400, 300)); panel.setLayout(new BorderLayout()); panel.add(chartPanel3, BorderLayout.CENTER); mainPanel.add(panel, new GridBagConstraints(1, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0)); chart = charts.get(3); panel = new JPanel(); ChartPanel chartPanel4 = new ChartPanel(chart); chartPanel4.setPreferredSize(new Dimension(400, 300)); panel.setLayout(new BorderLayout()); panel.add(chartPanel4, BorderLayout.CENTER); mainPanel.add(panel, new GridBagConstraints(1, 1, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 20, 20), 0, 0)); JDialog dialog = new JDialog(new JFrame(), true); dialog.setTitle("?"); dialog.setSize(850, 650); dialog.getContentPane().add(mainPanel); dialog.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame parentFrame = new JFrame(); parentFrame.setSize(500, 150);/*from w w w . ja v a 2s .c o m*/ JLabel jl = new JLabel(); jl.setText("Count : 0"); parentFrame.add(BorderLayout.CENTER, jl); parentFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); parentFrame.setVisible(true); final JDialog dlg = new JDialog(parentFrame, "Progress Dialog", true); JProgressBar dpb = new JProgressBar(0, 500); dlg.add(BorderLayout.CENTER, dpb); dlg.add(BorderLayout.NORTH, new JLabel("Progress...")); dlg.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); dlg.setSize(300, 75); dlg.setLocationRelativeTo(parentFrame); Thread t = new Thread(new Runnable() { public void run() { dlg.setVisible(true); } }); t.start(); for (int i = 0; i <= 500; i++) { jl.setText("Count : " + i); dpb.setValue(i); if (dpb.getValue() == 500) { dlg.setVisible(false); System.exit(0); } try { Thread.sleep(25); } catch (InterruptedException e) { e.printStackTrace(); } } dlg.setVisible(true); }
From source file:FrameKey.java
public static void main(String args[]) { final JFrame frame = new JFrame("Frame Key"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Action actionListener = new AbstractAction() { public void actionPerformed(ActionEvent actionEvent) { JDialog dialog = new EscapeDialog(frame, "Hey"); JButton button = new JButton("Okay"); ActionListener innerActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Dialog Button Selected"); }//w ww . j av a 2 s.com }; button.addActionListener(innerActionListener); dialog.getContentPane().add(button, BorderLayout.SOUTH); dialog.setSize(200, 200); dialog.show(); } }; JPanel content = (JPanel) frame.getContentPane(); KeyStroke stroke = KeyStroke.getKeyStroke("M"); InputMap inputMap = content.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(stroke, "OPEN"); content.getActionMap().put("OPEN", actionListener); frame.setSize(300, 300); frame.setVisible(true); }
From source file:de.dakror.virtualhub.server.dialog.BackupEditDialog.java
public static void show() throws JSONException { final JDialog dialog = new JDialog(Server.currentServer.frame, "Backup-Einstellungen", true); dialog.setSize(400, 250); dialog.setLocationRelativeTo(Server.currentServer.frame); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); JPanel cp = new JPanel(new SpringLayout()); cp.add(new JLabel("Zielverzeichnis:")); JPanel panel = new JPanel(); final JTextField path = new JTextField((Server.currentServer.settings.has("backup.path") ? Server.currentServer.settings.getString("backup.path") : ""), 10); panel.add(path);// w ww . j av a2 s .co m panel.add(new JButton(new AbstractAction("Whlen...") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { JFileChooser jfc = new JFileChooser((path.getText().length() > 0 ? new File(path.getText()) : new File(System.getProperty("user.home")))); jfc.setFileHidingEnabled(false); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setDialogTitle("Backup-Zielverzeichnis whlen"); if (jfc.showOpenDialog(dialog) == JFileChooser.APPROVE_OPTION) path.setText(jfc.getSelectedFile().getPath().replace("\\", "/")); } })); cp.add(panel); cp.add(new JLabel("")); cp.add(new JLabel("")); cp.add(new JButton(new AbstractAction("Abbrechen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } })); cp.add(new JButton(new AbstractAction("Speichern") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { try { if (path.getText().length() > 0) Server.currentServer.settings.put("backup.path", path.getText()); dialog.dispose(); } catch (JSONException e1) { e1.printStackTrace(); } } })); SpringUtilities.makeCompactGrid(cp, 3, 2, 6, 6, 6, 6); dialog.setContentPane(cp); dialog.pack(); dialog.setVisible(true); }
From source file:Main.java
/** * Resize a dialog to be a percentage of the total screen size * //w w w. j a v a 2 s.c o m * @param owner * @param dialog * @param percentage */ public static void resizeAndCentreDialogOnScreen(JDialog dialog, double percentage) { Dimension screenSize = toolkit.getScreenSize(); int width = (int) ((screenSize.width * percentage) / 100d); int height = (int) ((screenSize.height * percentage) / 100d); dialog.setSize(width, height); int x = (int) ((screenSize.width * 0.5f) - (width * 0.5f)); int y = (int) ((screenSize.height * .05f) - (height * 0.5f)); dialog.setLocation(x, y); }
From source file:de.dakror.virtualhub.client.dialog.ChooseCatalogDialog.java
public static void show(ClientFrame frame, final JSONArray data) { final JDialog dialog = new JDialog(frame, "Katalog whlen", true); dialog.setSize(400, 300); dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); dialog.addWindowListener(new WindowAdapter() { @Override/*from ww w .j av a 2 s . c o m*/ public void windowClosing(WindowEvent e) { Client.currentClient.disconnect(); System.exit(0); } }); JPanel contentPane = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0)); dialog.setContentPane(contentPane); DefaultListModel dlm = new DefaultListModel(); for (int i = 0; i < data.length(); i++) { try { dlm.addElement(data.getJSONObject(i).getString("name")); } catch (JSONException e) { e.printStackTrace(); } } final JList catalogs = new JList(dlm); catalogs.setDragEnabled(false); catalogs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane jsp = new JScrollPane(catalogs, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); jsp.setPreferredSize(new Dimension(396, 200)); contentPane.add(jsp); JPanel mods = new JPanel(new GridLayout(1, 2)); mods.setPreferredSize(new Dimension(50, 22)); mods.add(new JButton(new AbstractAction("+") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { String name = JOptionPane.showInputDialog(dialog, "Bitte geben Sie den Namen des neuen Katalogs ein.", "Katalog hinzufgen", JOptionPane.PLAIN_MESSAGE); if (name != null && name.length() > 0) { DefaultListModel dlm = (DefaultListModel) catalogs.getModel(); for (int i = 0; i < dlm.getSize(); i++) { if (dlm.get(i).toString().equals(name)) { JOptionPane.showMessageDialog(dialog, "Es existert bereits ein Katalog mit diesem Namen!", "Katalog bereits vorhanden!", JOptionPane.ERROR_MESSAGE); actionPerformed(e); return; } } try { dlm.addElement(name); JSONObject o = new JSONObject(); o.put("name", name); o.put("sources", new JSONArray()); o.put("tags", new JSONArray()); data.put(o); Client.currentClient.sendPacket(new Packet0Catalogs(data)); } catch (Exception e1) { e1.printStackTrace(); } } } })); mods.add(new JButton(new AbstractAction("-") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { if (catalogs.getSelectedIndex() != -1) { if (JOptionPane.showConfirmDialog(dialog, "Sind Sie sicher, dass Sie diesen\r\nKatalog unwiderruflich lschen wollen?", "Katalog lschen", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { DefaultListModel dlm = (DefaultListModel) catalogs.getModel(); data.remove(catalogs.getSelectedIndex()); dlm.remove(catalogs.getSelectedIndex()); try { Client.currentClient.sendPacket(new Packet0Catalogs(data)); } catch (IOException e1) { e1.printStackTrace(); } } } } })); contentPane.add(mods); JLabel l = new JLabel(""); l.setPreferredSize(new Dimension(396, 14)); contentPane.add(l); JSeparator sep = new JSeparator(JSeparator.HORIZONTAL); sep.setPreferredSize(new Dimension(396, 10)); contentPane.add(sep); JPanel buttons = new JPanel(new GridLayout(1, 2)); buttons.setPreferredSize(new Dimension(396, 22)); buttons.add(new JButton(new AbstractAction("Abbrechen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { Client.currentClient.disconnect(); System.exit(0); } })); buttons.add(new JButton(new AbstractAction("Katalog whlen") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { if (catalogs.getSelectedIndex() != -1) { try { Client.currentClient .setCatalog(new Catalog(data.getJSONObject(catalogs.getSelectedIndex()))); Client.currentClient.frame.setTitle("- " + Client.currentClient.getCatalog().getName()); dialog.dispose(); } catch (JSONException e1) { e1.printStackTrace(); } } } })); dialog.add(buttons); dialog.setLocationRelativeTo(frame); dialog.setResizable(false); dialog.setVisible(true); }