List of usage examples for java.awt Font BOLD
int BOLD
To view the source code for java.awt Font BOLD.
Click Source Link
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { @Override//from w w w . j a v a 2 s.c o m protected void paintComponent(Graphics g) { super.paintComponent(g); int y = 0; for (int size = 4; size <= 24; size += 2) { g.setFont(new Font("Arial", Font.BOLD, size)); g.drawString("Name", 0, y); int heightOfFont = g.getFontMetrics().getHeight(); y += heightOfFont; } } @Override public Dimension getPreferredSize() { return new Dimension(300, 300); } }; frame.add(panel); frame.setLocationByPlatform(true); frame.setVisible(true); frame.pack(); }
From source file:Main.java
public static void main(String arg[]) throws Exception { String yourText = "java2s.com"; BufferedImage bufferedImage = new BufferedImage(170, 30, BufferedImage.TYPE_INT_RGB); Graphics graphics = bufferedImage.getGraphics(); graphics.setColor(Color.LIGHT_GRAY); graphics.fillRect(0, 0, 200, 50);//w w w .j a v a2 s .co m graphics.setColor(Color.BLACK); graphics.setFont(new Font("Arial Black", Font.BOLD, 20)); graphics.drawString(yourText, 10, 25); ImageIO.write(bufferedImage, "jpg", new File("C:/Users/image.jpg")); System.out.println("Image Created"); }
From source file:BorderLayoutExample.java
public static void main(String[] args) { BorderSample bs = new BorderSample(); bs.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = bs.getContentPane(); pane.setLayout(new BorderLayout()); JLabel label = new JLabel("North", JLabel.CENTER); label.setFont(new Font("Courier", Font.BOLD, 36)); label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); pane.add(label, BorderLayout.NORTH); label = new JLabel("South", JLabel.CENTER); label.setFont(new Font("Courier", Font.BOLD, 36)); label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); pane.add(label, BorderLayout.SOUTH); label = new JLabel("East", JLabel.CENTER); label.setFont(new Font("Courier", Font.BOLD, 36)); label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); pane.add(label, BorderLayout.EAST); label = new JLabel("West", JLabel.CENTER); label.setFont(new Font("Courier", Font.BOLD, 36)); label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); pane.add(label, BorderLayout.WEST); label = new JLabel("Center", JLabel.CENTER); label.setFont(new Font("Courier", Font.BOLD, 36)); label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); pane.add(label, BorderLayout.CENTER); bs.setSize(400, 300);//from www . j a v a 2 s . c o m bs.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); Graphics g = img.getGraphics(); g.setColor(Color.red);/*from www. j av a2s.co m*/ g.setFont(new Font("Arial", Font.BOLD, 14)); g.drawString("Reference", 10, 80); int w = 100; int h = 100; int x = 1; int y = 1; int[] pixels = new int[w * h]; PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w); pg.grabPixels(); BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { bimg.setRGB(x + i, y + j, pixels[j * w + i]); } } FileOutputStream fout = new FileOutputStream("jpg.jpg"); JPEGImageEncoder jencoder = JPEGCodec.createJPEGEncoder(fout); JPEGEncodeParam enParam = jencoder.getDefaultJPEGEncodeParam(bimg); enParam.setQuality(1.0F, true); jencoder.setJPEGEncodeParam(enParam); jencoder.encode(bimg); fout.close(); }
From source file:ListeningJColorChooserSample.java
public static void main(String args[]) { JFrame frame = new JFrame("JColorChooser Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JLabel label = new JLabel("www.java2s.com", JLabel.CENTER); label.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48)); frame.add(label, BorderLayout.SOUTH); final JColorChooser colorChooser = new JColorChooser(label.getBackground()); ColorSelectionModel model = colorChooser.getSelectionModel(); ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { Color newForegroundColor = colorChooser.getColor(); label.setForeground(newForegroundColor); }/*from ww w.java2s . c om*/ }; model.addChangeListener(changeListener); frame.add(colorChooser, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("JColorChooser Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JLabel label = new JLabel("www.java2s.com", JLabel.CENTER); label.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48)); frame.add(label, BorderLayout.SOUTH); final JColorChooser colorChooser = new JColorChooser(label.getBackground()); colorChooser.setBorder(BorderFactory.createTitledBorder("Pick Color for java2s.com")); ColorSelectionModel model = colorChooser.getSelectionModel(); ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { Color newForegroundColor = colorChooser.getColor(); label.setForeground(newForegroundColor); }/*from www . j a va 2 s . c o m*/ }; model.addChangeListener(changeListener); frame.add(colorChooser, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:TreeChangedRenderer.java
public static void main(String args[]) { JFrame frame = new JFrame("Changed Renderer"); JTree tree = new JTree(); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); renderer.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 32)); int rowHeight = tree.getRowHeight(); if (rowHeight <= 0) { tree.setRowHeight(rowHeight - 1); }/*from w w w.j ava 2s .c o m*/ // Swap background colors Color backgroundSelection = renderer.getBackgroundSelectionColor(); renderer.setBackgroundSelectionColor(renderer.getBackgroundNonSelectionColor()); renderer.setBackgroundNonSelectionColor(backgroundSelection); // Swap text colors Color textSelection = renderer.getTextSelectionColor(); renderer.setTextSelectionColor(renderer.getTextNonSelectionColor()); renderer.setTextNonSelectionColor(textSelection); JScrollPane scrollPane = new JScrollPane(tree); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:ComponentHier.java
public static void main(String args[]) { JFrame frame = new JFrame("JComponent Hierarchy"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Font font = (Font) UIManager.get("Tree.font"); font = new Font(font.getFontName(), Font.BOLD, font.getSize() - 3); UIManager.put("Tree.font", font); Vector jEditorPaneVector = new NamedVector("JEditorPane", new Object[] { "JTextPane" }); Vector jTextFieldVector = new NamedVector("JTextField", new Object[] { "JPasswordField" }); Vector jTextComponentVector = new NamedVector("JTextComponent", new Object[] { jEditorPaneVector, "JTextArea", jTextFieldVector }); Vector jLayeredPaneVector = new NamedVector("JLayeredPane", new Object[] { "JDesktopPane" }); Vector jToggleButtonVector = new NamedVector("JToggleButton", new Object[] { "JCheckBox", "JRadioButton" }); Vector jMenuItemVector = new NamedVector("JMenuItem", new Object[] { "JCheckBoxMenuItem", "JMenu", "JRadioButtonMenuItem" }); Vector abstractButtonVector = new NamedVector("Abstract Button", new Object[] { "JButton", jMenuItemVector, jToggleButtonVector }); Object jComponentNodes[] = { abstractButtonVector, "JColorChooser", "JComboBox", "JFileChooser", "JInternalFrame", "JLabel", jLayeredPaneVector, "JList", "JMenuBar", "JOptionPane", "JPanel", "JPopupMenu", "JProgressBar", "JRootPane", "JScrollBar", "JScrollPane", "JSeparator", "JSlider", "JSplitPane", "JTabbedPane", "JTable", jTextComponentVector, "JToolBar", "JTree", "JViewPort" }; Vector jComponentVector = new NamedVector("JComponent", jComponentNodes); Object rootNodes[] = { jComponentVector }; Vector rootVector = new NamedVector("Root", rootNodes); JTree tree = new JTree(rootVector); tree.putClientProperty("JTree.lineStyle", "Angled"); JScrollPane scrollPane = new JScrollPane(tree); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(250, 480);/*from w w w . j av a 2 s . c o m*/ frame.setVisible(true); }
From source file:WriteImageType.java
static public void main(String args[]) throws Exception { try {//from w w w .ja v a 2 s . c o m int width = 200, height = 200; // TYPE_INT_ARGB specifies the image format: 8-bit RGBA packed // into integer pixels BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D ig2 = bi.createGraphics(); Font font = new Font("TimesRoman", Font.BOLD, 20); ig2.setFont(font); String message = "www.java2s.com!"; FontMetrics fontMetrics = ig2.getFontMetrics(); int stringWidth = fontMetrics.stringWidth(message); int stringHeight = fontMetrics.getAscent(); ig2.setPaint(Color.black); ig2.drawString(message, (width - stringWidth) / 2, height / 2 + stringHeight / 4); ImageIO.write(bi, "PNG", new File("c:\\yourImageName.PNG")); ImageIO.write(bi, "JPEG", new File("c:\\yourImageName.JPG")); ImageIO.write(bi, "gif", new File("c:\\yourImageName.GIF")); ImageIO.write(bi, "BMP", new File("c:\\yourImageName.BMP")); } catch (IOException ie) { ie.printStackTrace(); } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { PrinterJob pj = PrinterJob.getPrinterJob(); Book book = new Book(); PageFormat defaultFormat = new PageFormat(); defaultFormat = pj.defaultPage(defaultFormat); PageFormat landscapeFormat = new PageFormat(); landscapeFormat.setOrientation(PageFormat.LANDSCAPE); PagePrinter[] page = new PagePrinter[2]; int pageWidth = (int) defaultFormat.getImageableWidth(); int pageHeight = (int) defaultFormat.getImageableHeight(); Font font = new Font("Helvetica", Font.BOLD, 18); page[0] = new PagePrinter(); page[0].addPrintElement(new MyItem("AAA", font, 100, pageHeight / 2)); page[0].addPrintElement(new MyItem("line", 0, pageHeight, pageWidth, pageHeight)); page[1] = new PagePrinter(); page[1].addPrintElement(new MyItem("rectangle", 100, 100, pageWidth - 200, pageHeight - 200)); page[1].addPrintElement(new MyItem("oval", 120, 120, pageWidth - 240, pageHeight - 240)); book.append(page[0], defaultFormat); book.append(page[1], landscapeFormat); pj.setPageable(book);/*from www . j a va 2s . com*/ pj.print(); }