JButton showWaitBtn = new JButton(new ShowWaitAction("Show Wait Dialog")); JPanel panel = new JPanel(); panel.add(showWaitBtn); JFrame frame = new JFrame("Frame"); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); Window win = SwingUtilities.getWindowAncestor((AbstractButton)evt.getSource()); final JDialog dialog = new JDialog(win, "Dialog", ModalityType.APPLICATION_MODAL); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Please wait......."), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setLocationRelativeTo(win); dialog.setVisible(true);
public void init() { final JPanel panel = new JPanel(); panel.add(new JButton(new AbstractAction("Press Me") { Window win = SwingUtilities.getWindowAncestor(panel); System.out.println("win class: " + win.getClass().getCanonicalName()); JDialog dialog = new JDialog(win, "My Dialog", ModalityType.APPLICATION_MODAL); dialog.add(Box.createRigidArea(new Dimension(200, 200))); dialog.pack(); dialog.setLocationRelativeTo(win); dialog.setVisible(true); add(panel);
Window win = SwingUtilities.getWindowAncestor(this); console = new JDialog(win); consoleText = new JTextArea(); consoleText.setPreferredSize(new Dimension(500, 300)); console.add(new JScrollPane(consoleText)); console.pack(); console.setLocationByPlatform(true); console.setVisible(true);
public void run() { final JPanel panel1 = new JPanel(); panel1.add(new JButton(new AbstractAction("Show new option pane") { public void actionPerformed(ActionEvent e1) { final JPanel panel2= new JPanel(); panel2.add(new JButton(new AbstractAction("Dispose of this option pane") { public void actionPerformed(ActionEvent e2) { Component comp = (Component) e2.getSource(); Window win = SwingUtilities.getWindowAncestor(comp); if (win != null) { win.dispose();
if (!view.isShowing()) { view.setShowing(true); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); f.setSize(new Dimension(600, 400)); updateViewTitle(view, f); View aView = (View) i.next(); if (aView != view && aView.isShowing() && SwingUtilities.getWindowAncestor(aView.getComponent()). getLocation().equals(loc)) { loc.x += 22; addWindow(f, view); f.getContentPane().add(view.getComponent()); f.setVisible(true); view.start();
@Override public void run() { mainFrame = new JFrame("test"); mainFrame.setSize(300, 100); mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); mainFrame.setVisible(true); SwingUtilities.getWindowAncestor(e.getComponent()).setLocation(x, y); public void mousePressed(MouseEvent e) { Point pos = SwingUtilities.getWindowAncestor(e.getComponent()).getLocation();
for ( final ConverterSetup setup : setupAssignments.getConverterSetups() ) final JButton button = new JButton( new ColorIcon( getColor( setup ) ) ); button.addActionListener( new ActionListener() final Window frame = SwingUtilities.getWindowAncestor( this ); if ( frame != null ) frame.pack();
final Window win = new Window(SwingUtilities.getWindowAncestor(this)); win.setFocusable(true); win.add(tooltip); win.pack(); Point p = new Point(-3, -win.getHeight() - 3); SwingUtilities.convertPointToScreen(p, this); win.setVisible(true);
JFrame frame = new JFrame("WindowCommunication"); frame.getContentPane().add(new MyFramePanel()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); private JButton openDialogeBtn = new JButton("Open Dialog"); field.setFocusable(false); add(field); add(openDialogeBtn); Window win = SwingUtilities.getWindowAncestor(this); if (win != null) { dialog = new JDialog(win, "My Dialog", ModalityType.APPLICATION_MODAL); dialog.getContentPane().add(dialogPanel); dialog.pack(); dialog.setLocationRelativeTo(null); private JButton okButton = new JButton("OK"); Window win = SwingUtilities.getWindowAncestor(this); if (win != null) { win.dispose();
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); for (int i = 0; i < BUTTON_COUNT; i++) { panel.add(new JButton(new ButtonAction("Option " + (i + 1)))); dialog.add(panel); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); selection = e.getActionCommand(); Component c = (Component) e.getSource(); Window win = SwingUtilities.getWindowAncestor(c); win.dispose();
@Override protected void showPanel(final Container p) { getParent().add(p, "south,height 300!", // getParent().getComponentCount() - 1); getParent().doLayout(); getParent().revalidate(); SwingUtilities.getWindowAncestor(this).pack(); getParent().repaint(); EventQueue.invokeLater(() -> { p.setVisible(true); try { Thread.sleep(100); } catch (final InterruptedException exc) {} requestFocusInWindow(); }); }
private JTextField nameField = new JTextField(10); private JComboBox searchTermsCombo = new JComboBox(); private JButton addNewFieldBtn = new JButton("Add New Field"); private JButton submitBtn = new JButton("Submit"); private JPanel centerPanel = new JPanel(new GridBagLayout()); private int gridY = 0; centerPanel.add(new JLabel("Name:"), gbc); gbc = createGBC(1, gridY); centerPanel.add(nameField, gbc); gridY++; centerPanel.add(new JLabel("Search Terms:"), gbc); gbc = createGBC(1, gridY); centerPanel.add(searchTermsCombo, gbc); gridY++; Window win = SwingUtilities.getWindowAncestor(addNewFieldBtn); if (win != null) { win.pack(); win.setLocationRelativeTo(null);
JFrame frame = new JFrame("Simple Arithmetic Calculator"); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); g.setColor(Color.WHITE); FontMetrics fm = g.getFontMetrics(); Window window = SwingUtilities.getWindowAncestor(this); int y = fm.getAscent(); g.drawString(getWidth() + "x" + getHeight() + "; " + window.getWidth() + "x" + window.getHeight(), 0, y);
final JPanel centerPanel = new JPanel(new GridLayout(0, 3)); JButton addBtn = new JButton(new AbstractAction("Add Button") { centerPanel.add(new JButton("X")); centerPanel.revalidate(); centerPanel.repaint(); SwingUtilities.getWindowAncestor(centerPanel).pack(); btnPanel.add(addBtn); mainPanel.add(centerPanel, BorderLayout.CENTER); mainPanel.add(btnPanel, BorderLayout.PAGE_END); JFrame frame = new JFrame("GridLayoutEg"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
JButton closeButton = new JButton("Close Me"); closeButton.addActionListener(this); add(closeButton); public void actionPerformed(ActionEvent e) { Window win = SwingUtilities.getWindowAncestor(this); if (win != null) { JFrame frame = new JFrame("Close From JPanel"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new CloseFromJPanel()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
panel.add(new Calculator()); JFrame frame = new JFrame("Simple Arithmetic Calculator"); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); add(new JTextField(), BorderLayout.NORTH); }; for (String key : keys) { keysPane.add(new JButton(key)); add(keysPane); g.setColor(Color.WHITE); FontMetrics fm = g.getFontMetrics(); Window window = SwingUtilities.getWindowAncestor(this); int y = fm.getAscent(); g.drawString(getWidth() + "x" + getHeight() + "; " + window.getWidth() + "x" + window.getHeight(), 0, y);
private static void createAndShowGui() { JPanel panel = new JPanel(); panel.add(new JButton(new ShowMovingDialogAction())); JFrame frame = new JFrame("MovingDialog"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(panel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); panel.add(new JLabel("label")); panel.add(new JTextField("TextField", 10)); panel.add(new JButton("Button")); JFrame owner = (JFrame) SwingUtilities.getWindowAncestor((Component) e .getSource()); final JDialog dialog = new JDialog(owner, "Dialog", ModalityType.APPLICATION_MODAL); dialog.getContentPane().add(panel); dialog.pack(); dialog.setLocation(0, 0);
prefW--; prefH--; Window win = SwingUtilities.getWindowAncestor(ShrinkingGui.this); win.pack(); } else { ((Timer)e.getSource()).stop(); ShrinkingGui paintEg = new ShrinkingGui(); JFrame frame = new JFrame("Shrinking Gui"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(paintEg); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
mainPanel.add(textField1); mainPanel.add(new JButton(new AbstractAction("Exit") { Window win = SwingUtilities.getWindowAncestor(thisBtn); win.dispose(); JFrame frame = new JFrame("Frame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationRelativeTo(null); JPanel mainPanel2 = new JPanel(); mainPanel2.add(textField2); mainPanel2.add(new JButton(new AbstractAction("Submit") { Window win = SwingUtilities.getWindowAncestor(thisBtn); win.dispose(); JDialog dialog = new JDialog(frame, "Dialog", ModalityType.APPLICATION_MODAL); dialog.getContentPane().add(mainPanel2); dialog.pack(); dialog.setLocationRelativeTo(frame); dialog.setVisible(true); frame.setVisible(true);
northPanel.add(new JLabel("Provider:")); northPanel.add(providerField); btnPanel.add(new JButton("Copy to Clipboard")); btnPanel.add(new JButton("Clear")); btnPanel.add(new JButton(new ExitAction())); southPanel.add(btnPanel); Window win = SwingUtilities.getWindowAncestor(GetLetterTextGui.this); win.dispose(); GetLetterTextGui mainPanel = new GetLetterTextGui(); JFrame frame = new JFrame(GUI_TITLE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true);