List of usage examples for javax.swing JFrame setLocationRelativeTo
public void setLocationRelativeTo(Component c)
From source file:Main.java
/** * Packs, centers, and shows the frame./*from ww w . j a v a2s . c om*/ * * @param f */ public static void finalize(JFrame f) { f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
/** * Instances frame basics/*from w ww.ja v a2 s. c o m*/ * @param mainView Frame which has been created. */ public static void instanceDefaults(JFrame mainView) { mainView.setLocationRelativeTo(null); mainView.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); mainView.pack(); mainView.setVisible(true); }
From source file:misc.TextAreaPrintingDemo.java
public static void createAndShowGUI() { JFrame f = new TextAreaPrintingDemo(); f.setLocationRelativeTo(null); f.setVisible(true);/*w ww . j a va 2s.co m*/ }
From source file:FieldValidator.java
public static void createUI() { JFrame f = new JFrame("FieldValidator"); JComponent content = createContent(); f.add(content);/* w ww. j av a 2s.c om*/ f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Wallpaper.java
public static void createUI() { JFrame f = new JFrame("Wallpaper"); JPanel panel = createPanel(); LayerUI<JComponent> layerUI = new WallpaperLayerUI(); JLayer<JComponent> jlayer = new JLayer<JComponent>(panel, layerUI); f.add(jlayer);/*from www .ja va2s . c o m*/ f.setSize(300, 200); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Myopia.java
public static void createUI() { JFrame f = new JFrame("Myopia"); LayerUI<JComponent> layerUI = new BlurLayerUI(); JPanel panel = createPanel(); JLayer<JComponent> jlayer = new JLayer<JComponent>(panel, layerUI); f.add(jlayer);//from w w w . j a v a 2s .c o m f.setSize(300, 200); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Diva.java
public static void createUI() { JFrame f = new JFrame("Diva"); LayerUI<JPanel> layerUI = new SpotlightLayerUI(); JPanel panel = createPanel(); JLayer<JPanel> jlayer = new JLayer<JPanel>(panel, layerUI); f.add(jlayer);//from ww w. j a v a 2 s . c om f.setSize(300, 200); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:org.graphstream.algorithm.measure.ChartMeasure.java
/** * Output some charts according to a set of parameters. Actually, only one * chart is supported. According to {@link PlotParameters#outputType}, plot * is displayed on screen or saved in a file. * /*from w w w . j a v a 2s . c o m*/ * @param params * parameters used to plot * @param charts * charts to output * @throws PlotException */ public static void outputPlot(PlotParameters params, JFreeChart... charts) throws PlotException { if (charts == null || charts.length == 0) throw new PlotException("no chart"); if (charts.length > 1) throw new PlotException("multiple charts not yet supported"); JFreeChart chart = charts[0]; switch (params.outputType) { case SCREEN: ChartPanel panel = new ChartPanel(chart, params.width, params.height, params.width, params.height, params.width + 50, params.height + 50, true, true, true, true, true, true); JFrame frame = new JFrame(params.title); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLocationRelativeTo(null); frame.add(panel); frame.pack(); frame.setVisible(true); break; case JPEG: try { ChartUtilities.saveChartAsJPEG(new File(params.path), chart, params.width, params.height); } catch (IOException e) { throw new PlotException(e); } break; case PNG: try { ChartUtilities.saveChartAsPNG(new File(params.path), chart, params.width, params.height); } catch (IOException e) { throw new PlotException(e); } break; } }
From source file:GUI.Main.java
static private WebPanel createAdminPanel(String url, String firstName, String lastName, final int myId) throws IOException { mainPanel.setPaintFocus(true);// w w w .j av a 2s. c o m // Text field input Search textSearchField = new WebTextField(15); textSearchField.setInputPrompt("Search"); textSearchField.setInputPromptFont(textSearchField.getFont().deriveFont(Font.ROMAN_BASELINE)); textSearchField.setTrailingComponent(new WebImage("resources/search.png")); System.out.println("My id" + myId); // Boite Message WebButton boiteMessageButton = new WebButton("Ouvrir ma Boite Message"); boiteMessageButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFrame boiteFrame = new JFrame("Boite de messages"); boiteFrame.setLocationRelativeTo(null); JPanel boite = new JPanel(new BorderLayout()); boite.add(new BoiteReception(myId), BorderLayout.CENTER); boiteFrame.add(boite); boiteFrame.setIconImage(new ImageIcon(getClass().getResource("/images/message.png")).getImage()); boiteFrame.pack(); boiteFrame.setLocationRelativeTo(boite); boiteFrame.setVisible(true); } }); // Text Button Search WebButton SearchButton = new WebButton("Search"); SearchButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { new ListOfOffres1().openListOfOffresFrameagn(1, textSearchField.getText(), myId); } catch (IOException ex) { Logger.getLogger(ListOfOffres1.class.getName()).log(Level.SEVERE, null, ex); } } }); // Exit Button WebButton logOutButton = new WebButton("Exit"); logOutButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ListOfOffresFrame.setVisible(false); //you can't see me! ListOfOffresFrame.dispose(); //Destroy the JFrame object ListOfOffresFrame = null; System.exit(0); } }); // Text Button Retour exitButton = new WebButton("Retour"); exitButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Retour clicked"); ListOfOffres1.openPleaseWait(); try { System.out.println("aaaaaaaaaaaaaaaaaaaaaaaa" + myId); new ListOfOffres1().openListOfOffresFrameagn(0, "", myId); } catch (IOException ex) { Logger.getLogger(ListOfOffres1.class.getName()).log(Level.SEVERE, null, ex); } } }); final WebPanel descPanel = new WebPanel(false); GroupPanel OffrePanel = new GroupPanel(GroupingType.fillFirst, 5, false); descPanel.setOpaque(false); descPanel.setMargin(50, 50, 50, 50); mainPanel.setPaintFocus(true); mainPanel.setMargin(10); System.out.print(url); // load the image once mainPanel.setPreferredSize(new Dimension(300, 100)); OffrePanel.add(new GroupPanel(GroupingType.fillFirst, 5, false, loadImageX(url), new WebLabel("<html><body><h1><font color=#555555>" + firstName + " " + lastName + "</font></h1></body></html>", WebLabel.CENTER), textSearchField, SearchButton, new WhiteSpace(), new GroupPanel(GroupingType.fillFirst, false, new WhiteSpace(), boiteMessageButton, new GroupPanel(GroupingType.fillFirstAndLast, 5, true, exitButton, logOutButton)))); mainPanel.add(OffrePanel); return mainPanel; }
From source file:com.heliosdecompiler.bootstrapper.Bootstrapper.java
private static HeliosData loadHelios() throws IOException { System.out.println("Finding Helios implementation"); HeliosData data = new HeliosData(); boolean needsToDownload = !IMPL_FILE.exists(); if (!needsToDownload) { try (JarFile jarFile = new JarFile(IMPL_FILE)) { ZipEntry entry = jarFile.getEntry("META-INF/MANIFEST.MF"); if (entry == null) { needsToDownload = true;//from w w w .j av a 2 s. c om } else { Manifest manifest = new Manifest(jarFile.getInputStream(entry)); String ver = manifest.getMainAttributes().getValue("Implementation-Version"); try { data.buildNumber = Integer.parseInt(ver); data.version = manifest.getMainAttributes().getValue("Version"); data.mainClass = manifest.getMainAttributes().getValue("Main-Class"); } catch (NumberFormatException e) { needsToDownload = true; } } } catch (IOException e) { needsToDownload = true; } } if (needsToDownload) { URL latestJar = new URL(LATEST_JAR); System.out.println("Downloading latest Helios implementation"); FileOutputStream out = new FileOutputStream(IMPL_FILE); HttpURLConnection connection = (HttpURLConnection) latestJar.openConnection(); if (connection.getResponseCode() == 200) { int contentLength = connection.getContentLength(); if (contentLength > 0) { InputStream stream = connection.getInputStream(); byte[] buffer = new byte[1024]; int amnt; AtomicInteger total = new AtomicInteger(); AtomicBoolean stop = new AtomicBoolean(false); Thread progressBar = new Thread() { public void run() { JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); JLabel label = new JLabel(); label.setText("Downloading latest Helios build"); panel.add(label); GridLayout layout = new GridLayout(); layout.setColumns(1); layout.setRows(3); panel.setLayout(layout); JProgressBar pbar = new JProgressBar(); pbar.setMinimum(0); pbar.setMaximum(100); panel.add(pbar); JTextArea textArea = new JTextArea(1, 3); textArea.setOpaque(false); textArea.setEditable(false); textArea.setText("Downloaded 00.00MB/00.00MB"); panel.add(textArea); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setContentPane(panel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); while (!stop.get()) { SwingUtilities.invokeLater( () -> pbar.setValue((int) (100.0 * total.get() / contentLength))); textArea.setText("Downloaded " + bytesToMeg(total.get()) + "MB/" + bytesToMeg(contentLength) + "MB"); try { Thread.sleep(100); } catch (InterruptedException ignored) { } } frame.dispose(); } }; progressBar.start(); while ((amnt = stream.read(buffer)) != -1) { out.write(buffer, 0, amnt); total.addAndGet(amnt); } stop.set(true); return loadHelios(); } else { throw new IOException("Content-Length set to " + connection.getContentLength()); } } else if (connection.getResponseCode() == 404) { // Most likely bootstrapper is out of date throw new RuntimeException("Bootstrapper out of date!"); } else { throw new IOException(connection.getResponseCode() + ": " + connection.getResponseMessage()); } } return data; }