List of usage examples for javax.swing JFrame setLocationByPlatform
public void setLocationByPlatform(boolean locationByPlatform)
From source file:Main.java
public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton loadButton = new JButton("Display Image"); loadButton.addActionListener(ev -> { JFileChooser fc = new JFileChooser(System.getProperty("user.home")); fc.addChoosableFileFilter(/*from w w w .j a v a 2s . co m*/ new FileNameExtensionFilter("Image files", new String[] { "png", "jpg", "jpeg", "gif" })); if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { try { Image image = ImageIO.read(fc.getSelectedFile()); if (image != null) { JPanel panel = new JPanel(new BorderLayout(10, 10)); panel.add(new JLabel(fc.getSelectedFile().toString()), BorderLayout.NORTH); panel.add(new JLabel(new ImageIcon(image))); JOptionPane.showMessageDialog(frame, panel); } } catch (Exception ex) { ex.printStackTrace(); } } }); frame.add(loadButton); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:Main.java
public static final void main(String[] args) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane textPane = new JTextPane(); textPane.addMouseMotionListener(new MouseAdapter() { public void mouseMoved(MouseEvent e) { AttributeSet style = getAttributes(e); if (style != null && StyleConstants.getIcon(style) != null) { textPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } else { textPane.setCursor(Cursor.getDefaultCursor()); }//from w w w. j av a 2s . c o m } }); frame.add(new JScrollPane(textPane)); StyledDocument doc = (StyledDocument) textPane.getDocument(); SimpleAttributeSet style = new SimpleAttributeSet(); StyleConstants.setIcon(style, createImage()); doc.insertString(doc.getLength(), "this is a test", null); doc.insertString(doc.getLength(), "test", style); doc.insertString(doc.getLength(), "this is a test\n", null); doc.insertString(doc.getLength(), "another image", style); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:Main.java
public static void main(String... args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel contentPane = new JPanel(); contentPane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); JTextField tfield1 = new JTextField(10); JTextField tfield2 = new JTextField(10); FocusListener tfieldListener = new FocusListener() { @Override/*from w w w . java 2 s . c o m*/ public void focusGained(FocusEvent fe) { } @Override public void focusLost(FocusEvent fe) { String num1 = tfield1.getText().trim(); String num2 = tfield2.getText().trim(); if (num1 == null || num1.equals("")) num1 = "0"; if (num2 == null || num2.equals("")) num2 = "0"; System.out.println(Integer.toString(Integer.parseInt(num1) + Integer.parseInt(num2))); } }; tfield1.addFocusListener(tfieldListener); tfield2.addFocusListener(tfieldListener); ((AbstractDocument) tfield1.getDocument()).setDocumentFilter(new MyDocumentFilter()); ((AbstractDocument) tfield2.getDocument()).setDocumentFilter(new MyDocumentFilter()); contentPane.add(tfield1); contentPane.add(tfield2); frame.setContentPane(contentPane); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:Main.java
public static void showFrameWithToolBar(String toolBarPosition) { JPanel gui = new JPanel(new BorderLayout()); JToolBar tb = new JToolBar(); gui.add(tb, toolBarPosition);// w ww . j a v a 2 s . com tb.add(new JButton("Button 1")); tb.add(new JButton("Button 2")); tb.addSeparator(); tb.add(new JButton("Button 3")); tb.add(new JCheckBox("Check 1", true)); JFrame f = new JFrame(toolBarPosition); f.setContentPane(gui); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationByPlatform(true); f.pack(); f.setSize(400, 120); f.setVisible(true); }
From source file:it.unibo.alchemist.boundary.monitors.Generic2DDisplay.java
private static JFrame makeFrame(final String title, final JPanel content) { final JFrame frame = new JFrame(title); frame.getContentPane().add(content); frame.setLocationByPlatform(true); frame.pack();//w w w.ja v a 2 s . c o m frame.setVisible(true); return frame; }
From source file:org.obiba.onyx.jade.instrument.gehealthcare.CardiosoftInstrumentRunner.java
/** * Create an information dialog that tells the user to wait while the data is being processed. *///w w w .j a v a2 s. co m private void showProcessingDialog() { JPanel messagePanel = new JPanel(); messagePanel.setAlignmentX(Component.CENTER_ALIGNMENT); messagePanel.setLayout(new BoxLayout(messagePanel, BoxLayout.Y_AXIS)); JLabel message = new JLabel(ecgResourceBundle.getString("Message.ProcessingEcgMeasurement")); message.setFont(new Font(Font.DIALOG, Font.PLAIN, 20)); messagePanel.add(message); JLabel subMessage = new JLabel(ecgResourceBundle.getString("Message.ProcessingEcgMeasurementInstructions")); subMessage.setFont(new Font(Font.DIALOG, Font.PLAIN, 14)); subMessage.setForeground(Color.RED); messagePanel.add(subMessage); JFrame window = new JFrame(); window.add(messagePanel); window.pack(); // Make sure dialog stays on top of all other application windows. window.setAlwaysOnTop(true); window.setLocationByPlatform(true); // Center dialog horizontally at the bottom of the screen. Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); window.setLocation((screenSize.width - window.getWidth()) / 2, screenSize.height - window.getHeight() - 70); window.setEnabled(false); window.setVisible(true); }
From source file:cc.siara.csv_ml_demo.MultiLevelCSVSwingDemo.java
/** * Constructor that adds components to the container, sets layout and opens * with window// ww w .j a va 2 s. c om * * @param container */ public MultiLevelCSVSwingDemo(Container container) { if (container == null) container = this; if (container instanceof JFrame) { JFrame frame = (JFrame) container; frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setLocationByPlatform(true); frame.setTitle("Demonstration of Multi-level CSV parsing (csv_ml)"); } container.setSize(800, 600); container.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 6)); container.add(lblInput); container.add(cbExamples); container.add(lblInputSize); container.add(tfInputSize); container.add(lblDelimiter); container.add(cbDelimiter); container.add(tfDelimiter); container.add(btnAbout); container.add(taInputScroll); container.add(lblOutput); container.add(btnDDLDML); container.add(btnJSON); container.add(btnXML); container.add(btnXPath); container.add(tfXPath); container.add(cbPretty); container.add(taOutputScroll); container.add(lblOutputSize); container.add(tfOutputSize); container.add(btnToCSV); container.add(lblJDBCURL); container.add(tfDBURL); container.add(btnRunDDL); container.add(lblID); container.add(tfID); container.add(btnGetData); JTextField tfID = new JTextField("1", 4); taInput.setBorder(BorderFactory.createLineBorder(getForeground())); taOutput.setBorder(BorderFactory.createLineBorder(getForeground())); setInputText(); cbExamples.addActionListener(this); cbDelimiter.addActionListener(this); btnAbout.addActionListener(this); btnXML.addActionListener(this); btnDDLDML.addActionListener(this); btnJSON.addActionListener(this); btnToCSV.addActionListener(this); btnXPath.addActionListener(this); btnRunDDL.addActionListener(this); btnGetData.addActionListener(this); taInput.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent arg0) { isInputChanged = true; } public void keyReleased(KeyEvent arg0) { } public void keyPressed(KeyEvent arg0) { } }); tfInputSize.setEditable(false); tfOutputSize.setEditable(false); setVisible(true); }
From source file:org.deegree.tools.rendering.InteractiveWPVS.java
/** * @param args//from w w w.java2 s.co m * @throws IOException * @throws UnsupportedOperationException * @throws JAXBException * @throws OWSException * @throws ServiceInitException */ public static void main(String[] args) throws IOException, UnsupportedOperationException, JAXBException, OWSException, ServiceInitException { Options options = initOptions(); // for the moment, using the CLI API there is no way to respond to a help argument; see // https://issues.apache.org/jira/browse/CLI-179 if (args != null && args.length > 0) { for (String a : args) { if (a != null && a.toLowerCase().contains("help") || "-?".equals(a)) { printHelp(options); System.exit(1); } } } try { CommandLine line = new PosixParser().parse(options, args); String request = null; // request = // "http://localhost:8080/services/services?service=WPVS&request=GetView&version=0.4.0&crs=epsg:31466&ELEVATIONMODEL=Elevation&OUTPUTFORMAT=image%2Fjpeg&EXCEPTIONS=application/vnd.ogc.se_xml&ROLL=0&Boundingbox=2579816.5%2C5616304.5%2C2582519.5%2C5619007.5&DATETIME=2006-06-21T12:30:00&AOV=60&SCALE=1.0&BACKGROUND=cirrus&WIDTH=800&HEIGHT=600&BACKGROUNDCOLOR=0xc6d6e5&datasets=Buildings,Trees,aerophoto-2007&POI=2579778,5620865,50&YAW=273&PITCH=25&DISTANCE=842"; String configFile = line.getOptionValue(OPT_WPVS_CONFIG_FILE); LOG.info("Checking for JOGL."); JOGLChecker.check(); LOG.info("JOGL check ok."); InteractiveWPVS app = createWPVSInstance(configFile, request, line); JFrame frame = new JFrame("deegree interactive WPVS"); frame.getContentPane().add(app, BorderLayout.CENTER); frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); frame.setSize(800, 600); frame.setLocationByPlatform(true); frame.setVisible(true); frame.pack(); } catch (ParseException exp) { System.err.println("ERROR: Invalid command line: " + exp.getMessage()); } // System.exit( 0 ); }
From source file:org.swiftexplorer.SwiftExplorer.java
private static void openMainWindow(final MainPanel cp) throws IOException { JFrame frame = new JFrame(Configuration.INSTANCE.getAppName()); Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); float ratio = (float) 0.8; Dimension windowSize = new Dimension((int) (screenSize.getWidth() * ratio), (int) (screenSize.getHeight() * ratio)); frame.setSize(windowSize.getSize()); frame.setLocationByPlatform(true); frame.setIconImage(ImageIO.read(SwiftExplorer.class.getResource("/icons/logo.png"))); frame.getContentPane().add(cp);/*from w ww . ja va2 s. c om*/ frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (cp.onClose()) { System.exit(0); } } }); cp.setOwner(frame); frame.setJMenuBar(cp.createMenuBar()); // center the frame int x = (int) ((screenSize.getWidth() - frame.getWidth()) / 2); int y = (int) ((screenSize.getHeight() - frame.getHeight()) / 2); frame.setLocation(x, y); frame.setVisible(true); }