List of usage examples for javax.swing JFrame setLocationRelativeTo
public void setLocationRelativeTo(Component c)
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane pane = new JTextPane(); pane.setEditorKit(new CustomEditorKit()); pane.setText("Underline With Different Color"); StyledDocument doc = (StyledDocument) pane.getDocument(); MutableAttributeSet attrs = new SimpleAttributeSet(); attrs.addAttribute("Underline-Color", Color.red); doc.setCharacterAttributes(0, doc.getLength() - 1, attrs, true); JScrollPane sp = new JScrollPane(pane); frame.setContentPane(sp);/* www . jav a 2 s . c o m*/ frame.setPreferredSize(new Dimension(400, 300)); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static final void main(String[] args) { JFrame frame = new JFrame(); JPanel mainPanel = new JPanel(); JPanel buttonsPanel = new JPanel(); frame.add(mainPanel);/* w w w. ja v a2 s . co m*/ frame.add(buttonsPanel, BorderLayout.SOUTH); String[] options = { "S", "G", "I", "T" }; JComboBox comboBox = new JComboBox(options); comboBox.setRenderer(new MyComboBoxRenderer("COUNTRY")); comboBox.setSelectedIndex(-1); mainPanel.add(comboBox); JButton clearSelectionButton = new JButton("Clear selection"); clearSelectionButton.addActionListener(e -> { comboBox.setSelectedIndex(-1); }); buttonsPanel.add(clearSelectionButton); frame.pack(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); final JSlider slider = new JSlider(0, 150, 0); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); slider.setPreferredSize(new Dimension(150, 30)); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent event) { int value = slider.getValue(); if (value == 0) { System.out.println("0"); } else if (value > 0 && value <= 30) { System.out.println("value > 0 && value <= 30"); } else if (value > 30 && value < 80) { System.out.println("value > 30 && value < 80"); } else { System.out.println("max"); }/*from w w w .j a v a 2 s . co m*/ } }); f.add(slider); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:livecanvas.mesheditor.MeshEditor.java
public static void main(String[] args) throws Exception { // AlloyLookAndFeel.setProperty("alloy.licenseCode", // "2011/06/29#asidjoaisdjoasidjid@mailinator.com#lj8xv#1a193l"); // AlloyLookAndFeel.setProperty("alloy.isToolbarEffectsEnabled", // "false");/* w ww . j a v a2s .c o m*/ // try { // AlloyLookAndFeel alloyLnF = new AlloyLookAndFeel(); // alloyLnF.setTheme(new GlassTheme(), true); // UIManager.setLookAndFeel(alloyLnF); // } catch (UnsupportedLookAndFeelException ex) { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // } JFrame f = new JFrame("LiveCanvas - Mesh Editor"); final MeshEditor meshEditor = new MeshEditor(); f.setJMenuBar(meshEditor.getMenuBar()); f.getContentPane().add(meshEditor); f.getContentPane().add(meshEditor.getToolBar(), BorderLayout.NORTH); f.pack(); f.setLocationRelativeTo(null); f.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); // meshEditor.exit(); } }); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); f.setVisible(true); // meshEditor.open(new File("C:/Users/Jasleen/Desktop/prez.mesh")); }
From source file:Main.java
public static void main(String[] args) { JFrame fr = new JFrame(); fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JEditorPane pane = new JEditorPane(); pane.setEditorKit(new NewEditorKit()); pane.setText(//from w ww . j a v a 2 s .c o m "test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test "); StyledDocument doc = (StyledDocument) pane.getDocument(); MutableAttributeSet attr = new SimpleAttributeSet(); attr.addAttribute("strike-color", Color.red); doc.setCharacterAttributes(0, 9, attr, false); attr.addAttribute("strike-color", Color.blue); doc.setCharacterAttributes(10, 19, attr, false); JScrollPane sp = new JScrollPane(pane); fr.getContentPane().add(sp); fr.setSize(300, 300); fr.setLocationRelativeTo(null); fr.setVisible(true); }
From source file:tk.mystudio.ocr.OCRTest.java
public static void main(String[] args) { JFrame frame = new JFrame("??"); final JLabel label = new JLabel(new ImageIcon(), JLabel.CENTER); byte[] image = client.getCodeByte(Constants.LOGIN_CODE_URL); String randCodeByRob = OCR.read(image); label.setIcon(new ImageIcon(image)); label.setText(randCodeByRob);//from w w w . ja va 2 s . c o m label.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { byte[] image = client.getCodeByte(Constants.LOGIN_CODE_URL); String randCodeByRob = OCR.read(image); label.setIcon(new ImageIcon(image)); label.setText(randCodeByRob); System.out.println(randCodeByRob); } }); frame.add(label); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 200); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:acmi.l2.clientmod.l2_version_switcher.Main.java
public static void main(String[] args) { if (args.length != 3 && args.length != 4) { System.out.println("USAGE: l2_version_switcher.jar host game version <--splash> <filter>"); System.out.println("EXAMPLE: l2_version_switcher.jar " + L2.NCWEST_HOST + " " + L2.NCWEST_GAME + " 1 \"system\\*\""); System.out.println(/* w ww .j a v a2s . com*/ " l2_version_switcher.jar " + L2.PLAYNC_TEST_HOST + " " + L2.PLAYNC_TEST_GAME + " 48"); System.exit(0); } List<String> argsList = new ArrayList<>(Arrays.asList(args)); String host = argsList.get(0); String game = argsList.get(1); int version = Integer.parseInt(argsList.get(2)); Helper helper = new Helper(host, game, version); boolean available = false; try { available = helper.isAvailable(); } catch (IOException e) { System.err.print(e.getClass().getSimpleName()); if (e.getMessage() != null) { System.err.print(": " + e.getMessage()); } System.err.println(); } System.out.println(String.format("Version %d available: %b", version, available)); if (!available) { System.exit(0); } List<FileInfo> fileInfoList = null; try { fileInfoList = helper.getFileInfoList(); } catch (IOException e) { System.err.println("Couldn\'t get file info map"); System.exit(1); } boolean splash = argsList.remove("--splash"); if (splash) { Optional<FileInfo> splashObj = fileInfoList.stream() .filter(fi -> fi.getPath().contains("sp_32b_01.bmp")).findAny(); if (splashObj.isPresent()) { try (InputStream is = new FilterInputStream( Util.getUnzipStream(helper.getDownloadStream(splashObj.get().getPath()))) { @Override public int read() throws IOException { int b = super.read(); if (b >= 0) b ^= 0x36; return b; } @Override public int read(byte[] b, int off, int len) throws IOException { int r = super.read(b, off, len); if (r >= 0) { for (int i = 0; i < r; i++) b[off + i] ^= 0x36; } return r; } }) { new DataInputStream(is).readFully(new byte[28]); BufferedImage bi = ImageIO.read(is); JFrame frame = new JFrame("Lineage 2 [" + version + "] " + splashObj.get().getPath()); frame.setContentPane(new JComponent() { { setPreferredSize(new Dimension(bi.getWidth(), bi.getHeight())); } @Override protected void paintComponent(Graphics g) { g.drawImage(bi, 0, 0, null); } }); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } catch (IOException e) { e.printStackTrace(); } } else { System.out.println("Splash not found"); } return; } String filter = argsList.size() > 3 ? separatorsToSystem(argsList.get(3)) : null; File l2Folder = new File(System.getProperty("user.dir")); List<FileInfo> toUpdate = fileInfoList.parallelStream().filter(fi -> { String filePath = separatorsToSystem(fi.getPath()); if (filter != null && !wildcardMatch(filePath, filter, IOCase.INSENSITIVE)) return false; File file = new File(l2Folder, filePath); try { if (file.exists() && file.length() == fi.getSize() && Util.hashEquals(file, fi.getHash())) { System.out.println(filePath + ": OK"); return false; } } catch (IOException e) { System.out.println(filePath + ": couldn't check hash: " + e); return true; } System.out.println(filePath + ": need update"); return true; }).collect(Collectors.toList()); List<String> errors = Collections.synchronizedList(new ArrayList<>()); ExecutorService executor = Executors.newFixedThreadPool(16); CompletableFuture[] tasks = toUpdate.stream().map(fi -> CompletableFuture.runAsync(() -> { String filePath = separatorsToSystem(fi.getPath()); File file = new File(l2Folder, filePath); File folder = file.getParentFile(); if (!folder.exists()) { if (!folder.mkdirs()) { errors.add(filePath + ": couldn't create parent dir"); return; } } try (InputStream input = Util .getUnzipStream(new BufferedInputStream(helper.getDownloadStream(fi.getPath()))); OutputStream output = new BufferedOutputStream(new FileOutputStream(file))) { byte[] buffer = new byte[Math.min(fi.getSize(), 1 << 24)]; int pos = 0; int r; while ((r = input.read(buffer, pos, buffer.length - pos)) >= 0) { pos += r; if (pos == buffer.length) { output.write(buffer, 0, pos); pos = 0; } } if (pos != 0) { output.write(buffer, 0, pos); } System.out.println(filePath + ": OK"); } catch (IOException e) { String msg = filePath + ": FAIL: " + e.getClass().getSimpleName(); if (e.getMessage() != null) { msg += ": " + e.getMessage(); } errors.add(msg); } }, executor)).toArray(CompletableFuture[]::new); CompletableFuture.allOf(tasks).thenRun(() -> { for (String err : errors) System.err.println(err); executor.shutdown(); }); }
From source file:jeplus.gui.EPlusEditorPanel.java
public static void main(String[] args) { try {/*from w ww . jav a 2s. c om*/ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); // UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); // UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception ex) { System.err.println(ex); } JFrame frame = new JFrame("E+ idf TextPanel test"); frame.getContentPane().add(new EPlusEditorPanel()); //frame.getContentPane().add(new EPlusTextPanel (null, null, 1, null, null, null)); frame.setSize(800, 800); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String s = new Date().toString(); JTextPane jtp = new JTextPane(); StyledDocument doc = (StyledDocument) jtp.getDocument(); SimpleAttributeSet normal = new SimpleAttributeSet(); StyleConstants.setFontFamily(normal, "SansSerif"); StyleConstants.setFontSize(normal, 16); SimpleAttributeSet boldBlue = new SimpleAttributeSet(normal); StyleConstants.setBold(boldBlue, true); StyleConstants.setForeground(boldBlue, Color.blue); SimpleAttributeSet highAlert = new SimpleAttributeSet(boldBlue); StyleConstants.setFontSize(highAlert, 18); StyleConstants.setItalic(highAlert, true); StyleConstants.setForeground(highAlert, Color.red); doc.insertString(doc.getLength(), s + "\n", normal); doc.insertString(doc.getLength(), s + "\n", boldBlue); doc.insertString(doc.getLength(), s + "\n", highAlert); f.add(jtp);// w ww .j ava 2 s. com f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:PopupMenu.java
public static void main(String[] args) { JFrame frame = new JFrame("JPopupMenu"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Toolkit toolkit = frame.getToolkit(); final JPopupMenu menu = new JPopupMenu(); JMenuItem menuItemBeep = new JMenuItem("Beep"); menuItemBeep.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { toolkit.beep();/*www. j av a 2 s . com*/ } }); menu.add(menuItemBeep); JMenuItem menuItemClose = new JMenuItem("Close"); menuItemClose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); menu.add(menuItemClose); frame.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { if (e.getButton() == e.BUTTON3) { menu.show(e.getComponent(), e.getX(), e.getY()); } } }); frame.setSize(250, 200); frame.setLocationRelativeTo(null); frame.setVisible(true); }