List of usage examples for javax.swing JDialog getContentPane
public Container getContentPane()
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("Frame"); frame.add(Box.createRigidArea(new Dimension(400, 300))); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack();/*from www .j a v a 2 s . co m*/ frame.setVisible(true); JDialog dialog = new JDialog(frame, "Dialog", true); int condition = JPanel.WHEN_IN_FOCUSED_WINDOW; InputMap inputMap = ((JPanel) dialog.getContentPane()).getInputMap(condition); ActionMap actionMap = ((JPanel) dialog.getContentPane()).getActionMap(); String enter = "enter"; inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), enter); actionMap.put(enter, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); dialog.add(Box.createRigidArea(new Dimension(200, 200))); dialog.pack(); dialog.setLocationRelativeTo(frame); 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 w w .java2 s . c o m*/ 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[] a) { JDialog f = new JDialog(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/*from w w w . j a v a 2 s . co m*/ } }); JButton btOK = new JButton("Press Enter to click me, I am the default."); btOK.setToolTipText("Save and exit"); f.getRootPane().setDefaultButton(btOK); JPanel p = new JPanel(); p.add(btOK); p.add(new JButton("I am NOT the default.")); f.getContentPane().add(p); f.pack(); f.setSize(new Dimension(300, 200)); f.setVisible(true); }
From source file:DefaultButton.java
public static void main(String[] a) { JDialog f = new JDialog(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/*from w w w.j a v a 2 s . c om*/ } }); JButton btOK = new JButton("Press Enter to click me, I am the default."); btOK.setToolTipText("Save and exit"); f.getRootPane().setDefaultButton(btOK); JPanel p = new JPanel(); p.add(btOK); p.add(new JButton("I am NOT the default.")); f.getContentPane().add(p); f.pack(); f.setSize(new Dimension(300, 200)); f.show(); }
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"); }/*from w w w.j a v a 2s . 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: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 ww w .j av a 2s .c om*/ 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();// ww w. j ava2 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
/** * Sets the given action so it's invoked if the user hits the escape key. * @param dialog The dialog to attach the escape key. * @param abortAction The action that is invoked if the escape key is pressed. *///from w w w. j a v a 2s . c o m public static void setEscapeWindowAction(JDialog dialog, ActionListener abortAction) { if (abortAction != null) { ((JComponent) dialog.getContentPane()).registerKeyboardAction(abortAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); } }
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 {/*from ww w. ja v a 2 s .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: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 w w w . jav a2s . 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]); }