List of usage examples for javax.swing JFrame setSize
public void setSize(int width, int height)
The width and height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize .
From source file:LinesDashes1.java
public static void main(String[] args) { LinesDashes1 lines = new LinesDashes1(); JFrame frame = new JFrame("Lines"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(lines);// ww w . ja v a2 s .co m frame.setSize(280, 270); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { int ROWS = 100; JPanel content = new JPanel(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.add(new JLabel("Thanks for helping out. Use tab to move around.")); for (int i = 0; i < ROWS; i++) { JTextField field = new JTextField("" + i); field.setName("field#" + i); content.add(field);//from ww w . jav a2s .c o m } KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (!(evt.getNewValue() instanceof JComponent)) { return; } JViewport viewport = (JViewport) content.getParent(); JComponent focused = (JComponent) evt.getNewValue(); if (content.isAncestorOf(focused)) { Rectangle rect = focused.getBounds(); Rectangle r2 = viewport.getVisibleRect(); content.scrollRectToVisible( new Rectangle(rect.x, rect.y, (int) r2.getWidth(), (int) r2.getHeight())); } } }); JFrame window = new JFrame(); window.setContentPane(new JScrollPane(content)); window.setSize(200, 200); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); }
From source file:Rectangles.java
public static void main(String[] args) { Rectangles rects = new Rectangles(); JFrame frame = new JFrame("Rectangles"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(rects);//from ww w. j a v a 2s . c om frame.setSize(360, 300); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame("Main"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new Main()); frame.setSize(200, 300); frame.setLocationByPlatform(true);/*from ww w.j a v a2 s. co m*/ frame.setVisible(true); }
From source file:TreeSelectionOption.java
public static void main(String[] argv) { JTree tree = new JTree(); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(tree)); frame.setSize(380, 320); frame.setLocationRelativeTo(null);//w w w .j a v a2 s . c o m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextComponent textcomp = new JTextArea(); final UndoManager undo = new UndoManager(); Document doc = textcomp.getDocument(); JFrame f = new JFrame(); f.add(new JScrollPane(textcomp)); f.setSize(330, 300); f.setVisible(true);//w w w. jav a 2 s .c om doc.addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { undo.addEdit(evt.getEdit()); } }); textcomp.getActionMap().put("Undo", new AbstractAction("Undo") { public void actionPerformed(ActionEvent evt) { try { if (undo.canUndo()) { undo.undo(); } } catch (CannotUndoException e) { } } }); textcomp.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo"); textcomp.getActionMap().put("Redo", new AbstractAction("Redo") { public void actionPerformed(ActionEvent evt) { try { if (undo.canRedo()) { undo.redo(); } } catch (CannotRedoException e) { } } }); textcomp.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo"); }
From source file:GrayImage.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.add(new GrayImage()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.setLocationRelativeTo(null);//from w w w . j a v a 2 s . c o m frame.setVisible(true); }
From source file:Text.java
public static void main(String[] args) { Text text = new Text(); JFrame frame = new JFrame("Sonnet 55"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(text);/*from w w w.ja v a 2 s .co m*/ frame.setSize(500, 470); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final int columnCount = 10; final int side = 25; final int[][] grid = new int[50][columnCount]; JPanel panel = new JPanel() { public void paintComponent(Graphics g) { Font font = new Font("WingDings", Font.PLAIN, 14); g.setFont(font);/* w ww . j a va 2 s . co m*/ int off = 0; for (int i = 0; i < 256 * 256; i++) { if (font.canDisplay((char) i) == false) { continue; } off++; grid[off / columnCount][off % columnCount] = i; int x = off % columnCount * side; int y = (off / columnCount) * side + side; g.drawString(Character.toString((char) i), x, y); } } }; JFrame frame = new JFrame(); panel.setSize(300, 300); frame.getContentPane().add(panel); frame.setSize(300, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { final JTextPane pane = new JTextPane(); pane.setText("Some text"); JButton buttonButton = new JButton("Insert label"); buttonButton.addActionListener(e -> { JLabel label = new JLabel("label"); label.setAlignmentY(0.85f);//from ww w . j av a 2 s.c o m pane.insertComponent(label); }); JPanel panel = new JPanel(new BorderLayout()); panel.add(buttonButton, BorderLayout.SOUTH); panel.add(pane, BorderLayout.CENTER); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.setSize(400, 200); frame.setVisible(true); }