List of usage examples for javax.swing JFrame setLocation
@Override public void setLocation(int x, int y)
The method changes the geometry-related data.
From source file:Main.java
static void setFramePositon(JFrame inTargetFrame) { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); Dimension size = inTargetFrame.getSize(); // (ulrivo): full size on screen with less than 640 width if (d.width >= 640) { inTargetFrame.setLocation((d.width - size.width) / 2, (d.height - size.height) / 2); } else {// w w w . j a v a 2 s . c o m inTargetFrame.setLocation(0, 0); inTargetFrame.setSize(d); } }
From source file:UIUtilities.java
public static void setFrameLocationRelativeTo(JFrame f, Component c) { if (c == null) { // Setting the position of the dialog on the center of the screen // in 1.4 should be replaced by // f.setLocationRelativeTo(null); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); f.setLocation((int) d.getWidth() / 2 - (int) f.getPreferredSize().getWidth() / 2, (int) d.getHeight() / 2 - (int) f.getPreferredSize().getHeight() / 2); }/*w w w . j a v a 2 s .c o m*/ }
From source file:Main.java
public static void window_centered(JFrame frame) { frame.pack();/* w w w .j av a 2 s. c o m*/ Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int width = screenSize.width; int height = screenSize.height; int x = (width - frame.getWidth()) / 2; int y = (height - frame.getHeight()) / 2; frame.setLocation(x, y); }
From source file:Main.java
public static void moveToCenter(JFrame frame) { int windowWidth = frame.getWidth(); int windowHeight = frame.getHeight(); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int screenWidth = screenSize.width; int screenHeight = screenSize.height; frame.setLocation(screenWidth / 2 - windowWidth / 2, screenHeight / 2 - windowHeight / 2); }
From source file:ConsoleWindowTest.java
public static void init() { JFrame frame = new JFrame(); frame.setTitle("ConsoleWindow"); final JTextArea output = new JTextArea(); output.setEditable(false);/*from ww w . j a v a 2 s. co m*/ frame.add(new JScrollPane(output)); frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); frame.setLocation(DEFAULT_LEFT, DEFAULT_TOP); frame.setFocusableWindowState(false); frame.setVisible(true); // define a PrintStream that sends its bytes to the output text area PrintStream consoleStream = new PrintStream(new OutputStream() { public void write(int b) { } // never called public void write(byte[] b, int off, int len) { output.append(new String(b, off, len)); } }); // set both System.out and System.err to that stream System.setOut(consoleStream); System.setErr(consoleStream); }
From source file:Main.java
public static void centerFrame(JFrame frame) { GraphicsDevice defaultScreen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); Rectangle screenSize = defaultScreen.getDefaultConfiguration().getBounds(); int midx = screenSize.width / 2; int midy = screenSize.height / 2; int posx = midx - (frame.getWidth() / 2); int posy = midy - (frame.getHeight() / 2); frame.setLocation(posx, posy); }
From source file:levelBuilder.DialogMaker.java
/** * Displays key (i.e. legend) to the graph. *//*from w w w. j a v a 2s . c o m*/ private static void keyWindow() { JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0)); BufferedImage img1 = null; BufferedImage img2 = null; BufferedImage img3 = null; BufferedImage img4 = null; BufferedImage img5 = null; try { img1 = ImageIO.read(new File(imgDir + "green.png")); img2 = ImageIO.read(new File(imgDir + "red.png")); img3 = ImageIO.read(new File(imgDir + "blue.png")); img4 = ImageIO.read(new File(imgDir + "circle.png")); img5 = ImageIO.read(new File(imgDir + "square.png")); } catch (IOException e) { e.printStackTrace(); } panel.add(new JLabel("Initial Node", new ImageIcon(img1), SwingConstants.LEFT)); panel.add(new JLabel("End Node", new ImageIcon(img2), SwingConstants.LEFT)); panel.add(new JLabel("Intermediate Node", new ImageIcon(img3), SwingConstants.LEFT)); panel.add(new JLabel("Player Node", new ImageIcon(img4), SwingConstants.LEFT)); panel.add(new JLabel("NPC Node", new ImageIcon(img5), SwingConstants.LEFT)); JFrame frame = new JFrame("Key"); panel.setOpaque(true); frame.setContentPane(panel); frame.pack(); frame.setLocation(windowWidth, 0); frame.setVisible(true); verticalWindowPlacement += frame.getBounds().height + frame.getBounds().y; horizontalWindowPlacement += frame.getBounds().width; }
From source file:ch.admin.hermes.etl.load.HermesETLApplication.java
/** * erstellt einen Progress Dialog//from w w w.j a v a2s . c o m * @return */ private static JFrame createProgressDialog() { JFrame frame = new JFrame("HERMES 5 XML Model nach Fremdsystem/Format"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); progress = new JProgressBar(); progress.setStringPainted(true); //Create and set up the content pane. progress.setOpaque(true); //content panes must be opaque frame.setContentPane(progress); frame.setTitle("Schreibe nach Zielsystem/Format"); //Display the window. frame.pack(); frame.setSize(400, 100); frame.setLocation(100, 100); frame.setVisible(true); return frame; }
From source file:levelBuilder.DialogMaker.java
/** * Provides other action buttons.//from www. j ava 2 s . co m */ private static void actionWindow() { //Performs actions based on button pushes. class ActionHandler implements ActionListener { @Override public void actionPerformed(ActionEvent e) { switch (e.getActionCommand()) { case "edge": if (addedEdgeID != 0.0) { DialogNode n = g.getSource(addedEdgeID); int length; if (n.getChildren().length == 0) length = 0; else length = n.getChildren().length; DialogNode[] newChildren = new DialogNode[length + 1]; for (int c = 0; c < newChildren.length - 1; c++) newChildren[c] = n.getChildren()[c]; newChildren[newChildren.length - 1] = nodeMap.get(g.getDest(addedEdgeID).getText()); n.setChildren(newChildren); addedEdgeID = 0.0; } case "save": saveGraph(); case "check": //Checks for errors and displays them if they exist. ArrayList<String> errorList = new ArrayList<String>(); errorList = dg.check(); if (errorList.isEmpty()) { JOptionPane.showMessageDialog(null, "No errors!", null, JOptionPane.PLAIN_MESSAGE); } else { JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0)); for (String error : errorList) panel.add(new JLabel(error)); JOptionPane.showMessageDialog(null, panel, "Errors. Fix these to continue.", JOptionPane.PLAIN_MESSAGE); } case "reload": loadGraph(false); } } } JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0)); //Buttons JButton button3 = new JButton("New edge"); button3.setActionCommand("edge"); button3.addActionListener(new ActionHandler()); panel.add(button3); JButton button6 = new JButton("Save"); button6.setActionCommand("save"); button6.addActionListener(new ActionHandler()); panel.add(button6); JButton button7 = new JButton("Check"); button7.setActionCommand("check"); button7.addActionListener(new ActionHandler()); panel.add(button7); JButton button1 = new JButton("Reload"); button1.setActionCommand("reload"); button1.addActionListener(new ActionHandler()); panel.add(button1); JFrame frame = new JFrame("Other Input"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(panel); frame.pack(); frame.setLocation(windowWidth + horizontalWindowPlacement, 0); frame.setVisible(true); }
From source file:levelBuilder.DialogMaker.java
/** * Displays properties of the currently selected node. * Also allows changing of most node properties. *///from w w w . ja v a2 s . c o m private static void nodePropertiesWindow() { //Performs actions based on button pushes. class ActionHandler implements ActionListener { @Override public void actionPerformed(ActionEvent e) { switch (e.getActionCommand()) { case "probSet": //parsing new probSet string to double[] ArrayList<double[]> probSets = selectedNode.getProbSets(); if (probSetField.getText().equals("")) probSets.remove(strategy); else { String[] probSetInput = probSetField.getText().split(","); int numChildren = probSetInput.length; double[] newProbSet = new double[numChildren]; for (int c = 0; c < numChildren; c++) newProbSet[c] = Double.parseDouble(probSetInput[c]); if (probSets.size() > strategy)//TODO is this right? probSets.add(strategy, newProbSet); else probSets.set(strategy, newProbSet); } selectedNode.setProbSets(probSets); case "npc": if (isNPCBoxChecked) selectedNode.setNPC(); else selectedNode.setPC(); case "text": dg.changeNodeText(selectedNode, textField.getText()); case "strategy": strategy = Integer.parseInt(strategyField.getText()); } } } JPanel fieldPanel = new JPanel(new GridLayout(0, 1, 0, 0)); JPanel labelPanel = new JPanel(new GridLayout(0, 1, 0, 0)); JPanel buttonPanel = new JPanel(new GridLayout(0, 1, 0, 0)); JPanel masterPanel = new JPanel(new GridLayout(0, 3, 0, 0)); //Buttons, ckeckboxes, textboxes, and labels textField = new JTextField("May I buy your wand?", 10); fieldPanel.add(textField); labelPanel.add(new JLabel("Node Text")); JButton button1 = new JButton("Change"); button1.setActionCommand("text"); button1.addActionListener(new ActionHandler()); buttonPanel.add(button1); npcBox = new JCheckBox(); npcBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.DESELECTED) isNPCBoxChecked = false; else isNPCBoxChecked = true; } }); fieldPanel.add(npcBox); labelPanel.add(new JLabel("NPC")); JButton button2 = new JButton("Change"); button2.setActionCommand("npc"); button2.addActionListener(new ActionHandler()); buttonPanel.add(button2); childrenField = new JTextField("child1,child2", 10); fieldPanel.add(childrenField); labelPanel.add(new JLabel("Children")); JButton button3 = new JButton(""); buttonPanel.add(button3); probSetField = new JTextField("0.1,0.9", 10); fieldPanel.add(probSetField); labelPanel.add(new JLabel("Probability set")); JButton button4 = new JButton("Change"); button4.setActionCommand("probSet"); button4.addActionListener(new ActionHandler()); buttonPanel.add(button4); strategyField = new JTextField("0", 10); fieldPanel.add(strategyField); labelPanel.add(new JLabel("Strategy")); JButton button5 = new JButton("Change"); button5.setActionCommand("strategy"); button5.addActionListener(new ActionHandler()); buttonPanel.add(button5); masterPanel.add(buttonPanel); masterPanel.add(fieldPanel); masterPanel.add(labelPanel); JFrame frame = new JFrame("Node Properties"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fieldPanel.setOpaque(true); frame.setContentPane(masterPanel); frame.pack(); frame.setLocation(windowWidth, verticalWindowPlacement); frame.setVisible(true); verticalWindowPlacement += frame.getBounds().height; }