List of usage examples for javax.swing JDialog JDialog
public JDialog(Window owner, String title)
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JDialog dialog = new JDialog(frame, "Dialog"); dialog.pack();//from ww w .j ava 2 s . c o m dialog.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JDialog d1 = new JDialog((JFrame) null, "Dialog 1"); d1.setName("Dialog 1"); JDialog d2 = new JDialog((Window) null, "Dialog 2"); d2.setName("Dialog 2"); Frame f = new Frame(); f.setName("Frame 1"); Window w1 = new Window(f); w1.setName("Window 1"); Window w2 = new Window(null); w2.setName("Window 2"); Window[] windows = Window.getWindows(); for (Window window : windows) System.out.println(window.getName() + ": " + window.getClass()); }
From source file:MainClass.java
public static void main(String[] args) { JDialog d1 = new JDialog((JFrame) null, "Dialog 1"); d1.setName("Dialog 1"); JDialog d2 = new JDialog((Window) null, "Dialog 2"); d2.setName("Dialog 2"); Frame f = new Frame(); f.setName("Frame 1"); Window w1 = new Window(f); w1.setName("Window 1"); Window w2 = new Window(null); w2.setName("Window 2"); Window[] ownerlessWindows = Window.getOwnerlessWindows(); for (Window window : ownerlessWindows) System.out.println(window.getName() + ": " + window.getClass()); }
From source file:MainClass.java
public static void main(String[] args) { JDialog d1 = new JDialog((JFrame) null, "Dialog 1"); d1.setName("Dialog 1"); JDialog d2 = new JDialog((Window) null, "Dialog 2"); d2.setName("Dialog 2"); Frame f = new Frame(); f.setName("Frame 1"); Window w1 = new Window(f); w1.setName("Window 1"); Window w2 = new Window(null); w2.setName("Window 2"); System.out.println("FRAME WINDOWS"); Frame[] frames = Frame.getFrames(); for (Frame frame : frames) System.out.println(frame.getName() + ": " + frame.getClass()); }
From source file:Main.java
public static void main(String[] a) { JPanel panel = new JPanel(); JDialog dialog = new JDialog((JFrame) SwingUtilities.getWindowAncestor(panel), true); }
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);/* w w w . j av a 2 s. c o m*/ frame.addComponentListener(new ComponentAdapter() { Point lastLocation; @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(final String[] args) { JFrame frame = new JFrame("Frame"); JDialog dialog = new JDialog(frame, "Dialog"); frame.add(new JLabel("Content")); frame.addMouseListener(new MouseAdapter() { @Override/*from www . ja va 2s.c o m*/ public void mousePressed(MouseEvent arg0) { System.out.println("frame pressed"); System.out.println("dialog focused " + dialog.isFocused()); System.out.println("frame focused " + frame.isFocused()); super.mousePressed(arg0); } }); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); dialog.add(new JLabel("Content")); dialog.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent arg0) { super.focusLost(arg0); dialog.requestFocus(); } }); dialog.pack(); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JFrame parent = new JFrame("Parent Frame"); parent.setLayout(new FlowLayout()); parent.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); parent.setBounds(100, 100, 300, 200); parent.setVisible(true);//from w w w .jav a2 s .co m JDialog dialog1 = new JDialog(parent, "Dialog1 - Modeless Dialog"); dialog1.setBounds(200, 200, 300, 200); dialog1.setVisible(true); JDialog dialog2 = new JDialog(parent, "Dialog2 - Document-Modal Dialog", Dialog.ModalityType.DOCUMENT_MODAL); dialog2.setBounds(300, 300, 300, 200); JDialog dialog3 = new JDialog(dialog2, "Dialog3 - Modeless Dialog"); dialog3.setBounds(400, 400, 300, 200); dialog3.setVisible(true); dialog2.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JDialog dialog;//w ww. j ava 2s .c o m JList jlist; ActionListener otherListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("current"); } }; JButton okButton = new JButton("OK"); okButton.addActionListener(e -> close(true)); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(e -> close(false)); jlist = new JList(new String[] { "A", "B", "C", "D", "E", "F", "G" }); jlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jlist.setVisibleRowCount(5); JScrollPane scroll = new JScrollPane(jlist); JPanel buttonsPanel = new JPanel(new FlowLayout()); buttonsPanel.add(okButton); buttonsPanel.add(cancelButton); JPanel content = new JPanel(new BorderLayout()); content.add(scroll, BorderLayout.CENTER); content.add(buttonsPanel, BorderLayout.SOUTH); dialog = new JDialog((Frame) null, true); dialog.setContentPane(content); dialog.pack(); dialog.getRootPane().registerKeyboardAction(otherListener, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); dialog.getRootPane().registerKeyboardAction(otherListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); dialog.getRootPane().getInputMap().put(KeyStroke.getKeyStroke("SPACE"), "doSomething"); dialog.getRootPane().getActionMap().put("doSomething", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); 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 . ja v a2 s . co 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); }