List of usage examples for java.awt Font Font
private Font(String name, int style, float sizePts)
From source file:LabelDemo.java
public LabelDemo() { super("JLabel Demo"); setSize(600, 100);//www . ja v a2 s.c o m JPanel content = new JPanel(new GridLayout(1, 4, 4, 4)); JLabel label = new JLabel("Java2s"); label.setBackground(Color.white); content.add(label); label = new JLabel("Java2s", SwingConstants.CENTER); label.setOpaque(true); label.setBackground(Color.white); content.add(label); label = new JLabel("Java2s"); label.setFont(new Font("Helvetica", Font.BOLD, 18)); label.setOpaque(true); label.setBackground(Color.white); content.add(label); ImageIcon image = new ImageIcon("java2sLogo.gif"); label = new JLabel("Java2s", image, SwingConstants.RIGHT); label.setVerticalTextPosition(SwingConstants.TOP); label.setOpaque(true); label.setBackground(Color.white); content.add(label); getContentPane().add(content); setVisible(true); }
From source file:SwingSuspendResume.java
public SwingSuspendResume() { symbolTF = new JTextField(); symbolTF.setEditable(false);//from w ww . j a v a2 s . co m symbolTF.setFont(new Font("Monospaced", Font.BOLD, 26)); symbolTF.setHorizontalAlignment(JTextField.CENTER); final JButton suspendB = new JButton("Suspend"); final JButton resumeB = new JButton("Resume"); suspendB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { suspendNow(); } }); resumeB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { resumeNow(); } }); JPanel innerStackP = new JPanel(); innerStackP.setLayout(new GridLayout(0, 1, 3, 3)); innerStackP.add(symbolTF); innerStackP.add(suspendB); innerStackP.add(resumeB); this.setLayout(new FlowLayout(FlowLayout.CENTER)); this.add(innerStackP); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setFont(new Font("Serif", Font.PLAIN, 48)); FontRenderContext frc = g2.getFontRenderContext(); String s = "www.java2s.com"; Rectangle2D bounds = g2.getFont().getStringBounds(s, frc); float width = (float) bounds.getWidth(); int centerX = 100; int baselineY = 70; g2.drawString(s, centerX - width / 2, baselineY); }
From source file:no.met.jtimeseries.chart.ErrorPlot.java
public static XYPlot getMarinogramErrorPlot() { XYItemRenderer renderer = new StandardXYItemRenderer(); NumberAxis rangeAxis = new NumberAxis(); XYPlot plot = new XYPlot(null, null, rangeAxis, renderer); XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 0.5, 0.5); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); plot.addAnnotation(annotation);/*from ww w . ja v a2s.c o m*/ return plot; }
From source file:Main.java
public static Object getPropertyValue(Element element) { NamedNodeMap map = element.getAttributes(); map.removeNamedItem(NAME_ATTR);/*from ww w.j a v a2s.com*/ if (map.item(0).getNodeName().equals(STRING_ATTR)) return map.item(0).getNodeValue(); else if (map.item(0).getNodeName().equals(INTEGER_ATTR)) return new Integer(map.item(0).getNodeValue()); else if (map.item(0).getNodeName().equals(DOUBLE_ATTR)) return new Double(map.item(0).getNodeValue()); else if (map.item(0).getNodeName().equals(FLOAT_ATTR)) return new Float(map.item(0).getNodeValue()); else if (map.item(0).getNodeName().equals(BOOLEAN_ATTR)) return Boolean.valueOf(map.item(0).getNodeValue()); else if (map.item(0).getNodeName().equals(COLOR_ATTR)) { String[] rgb = map.item(0).getNodeValue().split(","); return new Color(new Integer(rgb[0]), new Integer(rgb[1]), new Integer(rgb[2])); } else if (map.item(0).getNodeName().equals(FONT_ATTR)) { String[] font = map.item(0).getNodeValue().split(","); return new Font(font[0], new Integer(font[1]), new Integer(font[2])); } else { return null; } }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String s = "www.java2s.com"; Font font = new Font("Serif", Font.PLAIN, 24); FontRenderContext frc = g2.getFontRenderContext(); GlyphVector gv = font.createGlyphVector(frc, s); g2.drawGlyphVector(gv, 40, 60);//from www . j a v a2s . co m }
From source file:MainClass.java
public void paint(Graphics g) { BufferedImage bim;//ww w . ja v a 2s . c o m TexturePaint tp; String mesg = "www.java2s.com"; Font myFont = new Font("Lucida Regular", Font.BOLD, 72); Color[] colors = { Color.red, Color.blue, Color.yellow, }; int width = 8, height = 8; bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bim.createGraphics(); for (int i = 0; i < width; i++) { g2.setPaint(colors[(i / 2) % colors.length]); g2.drawLine(0, i, i, 0); g2.drawLine(width - i, height, width, height - i); } Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight()); tp = new TexturePaint(bim, r); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setPaint(tp); g2d.setFont(myFont); g2d.drawString(mesg, 20, 100); }
From source file:org.jfree.chart.demo.LegendWrapperDemo1.java
private static JFreeChart createChart(PieDataset piedataset) { JFreeChart jfreechart = ChartFactory.createPieChart("Legend Wrapper Demo 1", piedataset, false, true, false);/*from w w w . j a v a 2 s . c o m*/ PiePlot pieplot = (PiePlot) jfreechart.getPlot(); pieplot.setLabelFont(new Font("SansSerif", 0, 12)); pieplot.setNoDataMessage("No data available"); pieplot.setCircular(true); pieplot.setLabelGap(0.02D); LegendTitle legendtitle = new LegendTitle(jfreechart.getPlot()); BlockContainer blockcontainer = new BlockContainer(new BorderArrangement()); blockcontainer.setFrame(new BlockBorder(1.0D, 1.0D, 1.0D, 1.0D)); LabelBlock labelblock = new LabelBlock("Legend Items:", new Font("SansSerif", 1, 12)); labelblock.setPadding(5D, 5D, 5D, 5D); blockcontainer.add(labelblock, RectangleEdge.TOP); LabelBlock labelblock1 = new LabelBlock("Source: http://www.jfree.org"); labelblock1.setPadding(8D, 20D, 2D, 5D); blockcontainer.add(labelblock1, RectangleEdge.BOTTOM); BlockContainer blockcontainer1 = legendtitle.getItemContainer(); blockcontainer1.setPadding(2D, 10D, 5D, 2D); blockcontainer.add(blockcontainer1); legendtitle.setWrapper(blockcontainer); legendtitle.setPosition(RectangleEdge.RIGHT); legendtitle.setHorizontalAlignment(HorizontalAlignment.LEFT); jfreechart.addSubtitle(legendtitle); return jfreechart; }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; String s = "\"www.java2s.com,\" www.java2s.com"; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font plainFont = new Font("Times New Roman", Font.PLAIN, 24); AttributedString as = new AttributedString(s); as.addAttribute(TextAttribute.FONT, plainFont); as.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 18, 22); g2.drawString(as.getIterator(), 24, 70); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; String s = "\"www.java2s.com,\" www.java2s.com"; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font plainFont = new Font("Times New Roman", Font.PLAIN, 24); AttributedString as = new AttributedString(s); as.addAttribute(TextAttribute.FONT, plainFont); as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1, 11); g2.drawString(as.getIterator(), 24, 70); }