List of usage examples for javax.swing JFrame getLocation
public Point getLocation()
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600, 400);//from w w w .j a v a 2 s. c o m frame.setVisible(true); Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> { System.out.println(frame.getLocation()); }, 0, 1000, TimeUnit.MILLISECONDS); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setUndecorated(true);//ww w . j a v a 2 s . c o m frame.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { point.x = e.getX(); point.y = e.getY(); } }); frame.addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { Point p = frame.getLocation(); frame.setLocation(p.x + e.getX() - point.x, p.y + e.getY() - point.y); } }); frame.setSize(300, 300); frame.setLocation(200, 200); frame.setLayout(new BorderLayout()); frame.getContentPane().add(new JLabel("Drag to move", JLabel.CENTER), BorderLayout.CENTER); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("Menu"); menuBar.add(menu); JMenuItem item = new JMenuItem("Exit"); item.addActionListener(e -> System.exit(0)); menu.add(item); frame.setJMenuBar(menuBar); frame.setVisible(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);/*from w w w. ja v a2s . 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(String[] args) { final JFrame frame = new JFrame(); frame.setUndecorated(true);//from w w w .j a va 2 s. c o m JButton button = new JButton("Close Me"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); frame.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { point.x = e.getX(); point.y = e.getY(); } }); frame.addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { Point p = frame.getLocation(); frame.setLocation(p.x + e.getX() - point.x, p.y + e.getY() - point.y); } }); frame.setSize(300, 300); frame.setLocation(200, 200); frame.setLayout(new BorderLayout()); frame.getContentPane().add(button, BorderLayout.NORTH); frame.getContentPane().add(new JLabel("Drag Me", JLabel.CENTER), BorderLayout.CENTER); frame.setVisible(true); }
From source file:UndoExample1.java
public static void main(String[] args) { try {// w w w. j a v a2s .com UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new UndoExample1(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(250, 300); f.setVisible(true); // Create and show a frame monitoring undoable edits JFrame undoMonitor = new JFrame("Undo Monitor"); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); undoMonitor.getContentPane().add(new JScrollPane(textArea)); undoMonitor.setBounds(f.getLocation().x + f.getSize().width, f.getLocation().y, 400, 200); undoMonitor.setVisible(true); pane.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { UndoableEdit edit = evt.getEdit(); textArea.append(edit.getPresentationName() + "(" + edit.toString() + ")\n"); } }); // Create and show a frame monitoring document edits JFrame editMonitor = new JFrame("Edit Monitor"); final JTextArea textArea2 = new JTextArea(); textArea2.setEditable(false); editMonitor.getContentPane().add(new JScrollPane(textArea2)); editMonitor.setBounds(undoMonitor.getLocation().x, undoMonitor.getLocation().y + undoMonitor.getSize().height, 400, 200); editMonitor.setVisible(true); pane.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent evt) { textArea2.append("Attribute change\n"); } public void insertUpdate(DocumentEvent evt) { textArea2.append("Text insertion\n"); } public void removeUpdate(DocumentEvent evt) { textArea2.append("Text removal\n"); } }); }
From source file:UndoExample5.java
public static void main(String[] args) { try {//from ww w . j a v a 2s . com UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new UndoExample5(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setSize(250, 300); f.setVisible(true); // Create and show a frame monitoring undoable edits JFrame undoMonitor = new JFrame("Undo Monitor"); final JTextArea textArea = new JTextArea(); textArea.setEditable(false); undoMonitor.getContentPane().add(new JScrollPane(textArea)); undoMonitor.setBounds(f.getLocation().x + f.getSize().width, f.getLocation().y, 400, 200); undoMonitor.setVisible(true); pane.getDocument().addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { UndoableEdit edit = evt.getEdit(); textArea.append(edit.getPresentationName() + "(" + edit.toString() + ")\n"); } }); // Create and show a frame monitoring document edits JFrame editMonitor = new JFrame("Edit Monitor"); final JTextArea textArea2 = new JTextArea(); textArea2.setEditable(false); editMonitor.getContentPane().add(new JScrollPane(textArea2)); editMonitor.setBounds(undoMonitor.getLocation().x, undoMonitor.getLocation().y + undoMonitor.getSize().height, 400, 200); editMonitor.setVisible(true); pane.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent evt) { textArea2.append("Attribute change\n"); } public void insertUpdate(DocumentEvent evt) { textArea2.append("Text insertion\n"); } public void removeUpdate(DocumentEvent evt) { textArea2.append("Text removal\n"); } }); }
From source file:Main.java
public static void setCenterOfParent(JFrame parent, JDialog dialog) { Point parentPosition = parent.getLocation(); Dimension parentSize = parent.getSize(); Dimension size = dialog.getSize(); Point position = new Point(parentPosition.x + (parentSize.width / 2 - size.width / 2), parentPosition.y + (parentSize.height / 2 - size.height / 2)); dialog.setLocation(position);/* w ww. j ava 2s . co m*/ }
From source file:StdErrOutWindows.java
public StdErrOutWindows() { JScrollPane pain = new JScrollPane(outArea); JFrame outFrame = new JFrame("out"); outFrame.getContentPane().add(pain); outFrame.setVisible(true);//from w w w . j a v a 2 s .c om pain = new JScrollPane(errArea); JFrame errFrame = new JFrame("err"); errFrame.getContentPane().add(pain); errFrame.setLocation(errFrame.getLocation().x + 20, errFrame.getLocation().y + 20); errFrame.setVisible(true); System.setOut(new PrintStream(new JTextAreaOutputStream(outArea))); System.setErr(new PrintStream(new JTextAreaOutputStream(errArea))); }
From source file:components.Framework.java
public void makeNewWindow() { JFrame frame = new MyFrame(this); numWindows++;/* w ww. ja v a2 s . c o m*/ System.out.println("Number of windows: " + numWindows); if (lastLocation != null) { //Move the window over and down 40 pixels. lastLocation.translate(40, 40); if ((lastLocation.x > maxX) || (lastLocation.y > maxY)) { lastLocation.setLocation(0, 0); } frame.setLocation(lastLocation); } else { lastLocation = frame.getLocation(); } System.out.println("Frame location: " + lastLocation); frame.setVisible(true); }
From source file:Framework.java
public void makeNewWindow() { JFrame frame = new MyFrame(this); numWindows++;/*from www . ja v a 2 s .c o m*/ System.out.println("Number of windows: " + numWindows); if (lastLocation != null) { // Move the window over and down 40 pixels. lastLocation.translate(40, 40); if ((lastLocation.x > maxX) || (lastLocation.y > maxY)) { lastLocation.setLocation(0, 0); } frame.setLocation(lastLocation); } else { lastLocation = frame.getLocation(); } System.out.println("Frame location: " + lastLocation); frame.setVisible(true); }