List of usage examples for java.awt Dimension Dimension
public Dimension(int width, int height)
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Overlay Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { public boolean isOptimizedDrawingEnabled() { return false; }// w ww .j a v a 2 s . c o m }; LayoutManager overlay = new OverlayLayout(panel); panel.setLayout(overlay); JButton button = new JButton("Small"); button.setMaximumSize(new Dimension(25, 25)); button.setBackground(Color.white); button.setAlignmentX(0.0f); button.setAlignmentY(0.0f); panel.add(button); button = new JButton("Medium"); button.setMaximumSize(new Dimension(50, 50)); button.setBackground(Color.gray); button.setAlignmentX(0.0f); button.setAlignmentY(0.0f); panel.add(button); button = new JButton("Large"); button.setMaximumSize(new Dimension(100, 100)); button.setBackground(Color.black); button.setAlignmentX(0.0f); button.setAlignmentY(0.0f); panel.add(button); frame.add(panel, BorderLayout.CENTER); frame.setSize(400, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { int SIZE = 14; String FONT = "Dialog"; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane tp = new JTextPane(); tp.setFont(new Font(FONT, Font.PLAIN, SIZE)); tp.setPreferredSize(new Dimension(400, 300)); StyledDocument doc = tp.getStyledDocument(); Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style boldStyle = doc.addStyle("bold", defaultStyle); StyleConstants.setBold(boldStyle, true); String boldText = "this is bold test"; String plainText = "this is plain."; doc.insertString(doc.getLength(), boldText, boldStyle); doc.insertString(doc.getLength(), plainText, defaultStyle); JPanel panel = new JPanel(); panel.add(tp);/*from w w w. j a va 2 s . c o m*/ JComboBox<String> zoomCombo = new JComboBox<String>( new String[] { "0.75", "1.00", "1.50", "1.75", "2.00" }); zoomCombo.addActionListener(e -> { String s = (String) zoomCombo.getSelectedItem(); double scale = new Double(s).doubleValue(); int size = (int) (SIZE * scale); tp.setFont(new Font(FONT, Font.PLAIN, size)); }); zoomCombo.setSelectedItem("1.00"); JPanel optionsPanel = new JPanel(); optionsPanel.add(zoomCombo); panel.setBackground(Color.WHITE); frame.add(panel, BorderLayout.CENTER); frame.add(optionsPanel, BorderLayout.NORTH); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { String[] columns = { "Name", "Age" }; Object[][] content = { { "R", new Integer(24) }, { "A", new Integer(25) }, { "J", new Integer(30) }, { "A", new Integer(32) }, { "S", new Integer(27) } }; JTable table = new JTable(content, columns); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel jPanel = new JPanel(new GridLayout(2, 0)); jPanel.setOpaque(true);//from w w w. j av a 2 s . c o m table.setPreferredScrollableViewportSize(new Dimension(500, 70)); jPanel.add(new JScrollPane(table)); /* Add the panel to the JFrame */ frame.add(jPanel); /* Display the JFrame window */ frame.pack(); frame.setVisible(true); table.print(); }
From source file:Main.java
public static void main(String[] args) { final StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append("<body><ol>"); Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); for (Font font : fonts) { String name = font.getName(); sb.append("<li style='font-family: " + name + "; font-size: 20px;'>"); sb.append(name);/*from w w w .j a va 2 s . co m*/ } JScrollPane sp = new JScrollPane(new JLabel(sb.toString())); Dimension d = sp.getPreferredSize(); sp.setPreferredSize(new Dimension(d.width, 150)); JOptionPane.showMessageDialog(null, sp); }
From source file:Main.java
public static void main(String[] args) { JFrame dialog = new JFrame(); dialog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); dialog.setResizable(true);/*from w w w. ja v a2 s .c o m*/ JPanel guiHolder = new JPanel(); guiHolder.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.anchor = GridBagConstraints.PAGE_START; gbc.weightx = 1.0; gbc.weighty = 1.0; guiHolder.add(new JLabel("my test"), gbc); dialog.add(guiHolder); dialog.setSize(new Dimension(320, 240)); dialog.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JPanel main = new JPanel(new GridLayout(2, 1)); JPanel scrollBarPanel = new JPanel(); final JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 48, 0, 255); int height = scrollBar.getPreferredSize().height; scrollBar.setPreferredSize(new Dimension(175, height)); scrollBarPanel.add(scrollBar);//from w ww. j a v a2 s . c o m main.add(scrollBarPanel); JPanel sliderPanel = new JPanel(); final JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 255, 128); slider.setMajorTickSpacing(48); slider.setMinorTickSpacing(16); slider.setPaintTicks(true); sliderPanel.add(slider); main.add(sliderPanel); frame.add(main, BorderLayout.CENTER); scrollBar.addAdjustmentListener(new AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent e) { System.out.println("JScrollBar's current value = " + scrollBar.getValue()); } }); slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("JSlider's current value = " + slider.getValue()); } }); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { DefaultListModel<String> model = new DefaultListModel<>(); JList<String> sList = new JList<>(model); for (int i = 0; i < 100; i++) { model.addElement("String " + i); }/* w w w .ja v a 2 s . c o m*/ sList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); sList.setVisibleRowCount(-1); sList.setLayoutOrientation(JList.HORIZONTAL_WRAP); JFrame frame = new JFrame("Foo001"); frame.getContentPane().add(new JScrollPane(sList)); frame.getContentPane().setPreferredSize(new Dimension(400, 300)); 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) { JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String text = "A JTextArea object represents a multiline area for displaying text. " + "You can change the number of lines that can be displayed at a time, " + "as well as the number of columns. You can wrap lines and words too. " + "You can also put your JTextArea in a JScrollPane to make it scrollable."; JTextArea textAreal = new JTextArea(text, 5, 10); textAreal.setPreferredSize(new Dimension(100, 100)); JTextArea textArea2 = new JTextArea(text, 5, 10); textArea2.setPreferredSize(new Dimension(100, 100)); JScrollPane scrollPane = new JScrollPane(textArea2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); textAreal.setLineWrap(true);/*from www. j av a 2s . c o m*/ textArea2.setLineWrap(true); frame.add(textAreal); frame.add(scrollPane); frame.pack(); frame.setVisible(true); }
From source file:GTKLookAndFeelDemo.java
public static void main(String[] args) { try {/*from ww w .j a v a 2s . c o m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); } catch (Exception e) { e.printStackTrace(); } JLabel label = new JLabel("Label"); JTextField field = new JTextField("www.java2s.com!"); JList list = new JList(new String[] { "A", "B", "C" }); JScrollPane listPane = new JScrollPane(list); listPane.setPreferredSize(new Dimension(250, 100)); JScrollPane treePane = new JScrollPane(new JTree()); treePane.setPreferredSize(new Dimension(250, 100)); JButton button = new JButton("Click me"); JPanel cp = new JPanel(); cp.add(label); cp.add(field); cp.add(listPane); cp.add(treePane); cp.add(button); JFrame frame = new JFrame(); frame.setTitle("Windows Look and Feel Demo"); frame.setPreferredSize(new Dimension(280, 300)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(cp); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JDialog f = new JDialog(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/*w w w. j a va 2 s.co m*/ } }); JButton btOK = new JButton("Press Enter to click me, I am the default."); btOK.setToolTipText("Save and exit"); f.getRootPane().setDefaultButton(btOK); JPanel p = new JPanel(); p.add(btOK); p.add(new JButton("I am NOT the default.")); f.getContentPane().add(p); f.pack(); f.setSize(new Dimension(300, 200)); f.setVisible(true); }