List of usage examples for java.awt Font Font
private Font(String name, int style, float sizePts)
From source file:ResourceModExample.java
public static void main(String[] args) { Border border = BorderFactory.createRaisedBevelBorder(); Border tripleBorder = new CompoundBorder(new CompoundBorder(border, border), border); UIManager.put("Button.border", tripleBorder); UIManager.put("InternalFrame.closeIcon", new ImageIcon("close.gif")); UIManager.put("InternalFrame.iconizeIcon", new ImageIcon("iconify.gif")); UIManager.put("InternalFrame.maximizeIcon", new ImageIcon("maximize.gif")); UIManager.put("InternalFrame.altMaximizeIcon", new ImageIcon("altMax.gif")); UIManager.put("InternalFrame.titleFont", new Font("Serif", Font.ITALIC, 12)); UIManager.put("ScrollBar.width", new Integer(30)); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = f.getContentPane(); JDesktopPane desk = new JDesktopPane(); c.add(desk, BorderLayout.CENTER); JButton cut = new JButton("Cut"); JButton copy = new JButton("Copy"); JButton paste = new JButton("Paste"); JPanel p = new JPanel(new FlowLayout()); p.add(cut);/*from w ww .j a v a 2s . c om*/ p.add(copy); p.add(paste); c.add(p, BorderLayout.SOUTH); JInternalFrame inf = new JInternalFrame("MyFrame", true, true, true, true); JLabel l = new JLabel(new ImageIcon("luggage.jpeg")); JScrollPane scroll = new JScrollPane(l); inf.setContentPane(scroll); inf.setBounds(10, 10, 350, 280); desk.add(inf); inf.setVisible(true); f.setSize(380, 360); f.setVisible(true); }
From source file:CreateColorSamplePopup.java
public static void main(String args[]) { JFrame frame = new JFrame("JColorChooser Create Popup Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); final JButton button = new JButton("Pick to Change Background"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Color initialBackground = button.getBackground(); final JColorChooser colorChooser = new JColorChooser(initialBackground); // colorChooser.setPreviewPanel(new JPanel()); final JLabel previewLabel = new JLabel("I Love Swing", JLabel.CENTER); previewLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48)); colorChooser.setPreviewPanel(previewLabel); // Bug workaround colorChooser.updateUI();// ww w.j av a 2 s. c o m // For okay button selection, change button background to // selected color ActionListener okActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Color newColor = colorChooser.getColor(); if (newColor.equals(button.getForeground())) { System.out.println("Color change rejected"); } else { button.setBackground(colorChooser.getColor()); } } }; // For cancel button selection, change button background to red ActionListener cancelActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { button.setBackground(Color.red); } }; final JDialog dialog = JColorChooser.createDialog(null, "Change Button Background", true, colorChooser, okActionListener, cancelActionListener); // Wait until current event dispatching completes before showing // dialog Runnable showDialog = new Runnable() { public void run() { dialog.show(); } }; SwingUtilities.invokeLater(showDialog); } }; button.addActionListener(actionListener); contentPane.add(button, BorderLayout.CENTER); frame.setSize(300, 100); frame.setVisible(true); }
From source file:com.ohalo.cn.awt.JFreeChartTest3.java
public static void main(String[] args) throws Exception { JFreeChart chart = ChartFactory.createPieChart("???", getDataset(), true, true, false);//from ww w . j av a 2s. c om chart.setTitle(new TextTitle("??", new Font("", Font.BOLD + Font.ITALIC, 20))); LegendTitle legend = chart.getLegend(0);// Legend legend.setItemFont(new Font("", Font.BOLD, 14)); PiePlot plot = (PiePlot) chart.getPlot();// Plot plot.setLabelFont(new Font("", Font.BOLD, 16)); OutputStream os = new FileOutputStream("company.jpeg");// ??FileOutputStream? ChartUtilities.writeChartAsJPEG(os, chart, 1000, 800); // ??applicationchart??JPEG?3?4? os.close();// ? }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); final JFormattedTextField textField1 = new JFormattedTextField(new Float(10.01)); textField1.setFormatterFactory(new AbstractFormatterFactory() { @Override//from w ww. jav a2s . c o m public AbstractFormatter getFormatter(JFormattedTextField tf) { NumberFormat format = DecimalFormat.getInstance(); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); format.setRoundingMode(RoundingMode.HALF_UP); InternationalFormatter formatter = new InternationalFormatter(format); formatter.setAllowsInvalid(false); formatter.setMinimum(0.0); formatter.setMaximum(1000.00); return formatter; } }); Map attributes = (new Font("Serif", Font.BOLD, 16)).getAttributes(); attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); final JFormattedTextField textField2 = new JFormattedTextField(new Float(10.01)); textField2.setFormatterFactory(new AbstractFormatterFactory() { @Override public AbstractFormatter getFormatter(JFormattedTextField tf) { NumberFormat format = DecimalFormat.getInstance(); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); format.setRoundingMode(RoundingMode.HALF_UP); InternationalFormatter formatter = new InternationalFormatter(format); formatter.setAllowsInvalid(false); formatter.setMinimum(0.0); formatter.setMaximum(1000.00); return formatter; } }); textField2.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } @Override public void insertUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } @Override public void removeUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } private void printIt(DocumentEvent documentEvent) { DocumentEvent.EventType type = documentEvent.getType(); double t1a1 = (((Number) textField2.getValue()).doubleValue()); if (t1a1 > 100) { textField2.setFont(new Font(attributes)); textField2.setForeground(Color.red); } else { textField2.setFont(new Font("Serif", Font.BOLD, 16)); textField2.setForeground(Color.black); } } }); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(textField1, BorderLayout.NORTH); frame.add(textField2, BorderLayout.SOUTH); frame.setVisible(true); frame.pack(); }
From source file:Bouncer.java
public static void main(String[] args) { final Bouncer bouncer = new Bouncer(); Frame f = new AnimationFrame(bouncer); f.setFont(new Font("Serif", Font.PLAIN, 12)); f.setSize(200, 200);/*from www . j a v a 2s . com*/ Panel controls = new Panel(); controls.add(bouncer.createCheckbox("Anti.", Bouncer.ANTIALIASING)); controls.add(bouncer.createCheckbox("Trans.", Bouncer.TRANSFORM)); controls.add(bouncer.createCheckbox("Gradient", Bouncer.GRADIENT)); controls.add(bouncer.createCheckbox("Outline", Bouncer.OUTLINE)); controls.add(bouncer.createCheckbox("Dotted", Bouncer.DOTTED)); controls.add(bouncer.createCheckbox("Axes", Bouncer.AXES)); controls.add(bouncer.createCheckbox("Clip", Bouncer.CLIP)); f.add(controls, BorderLayout.NORTH); f.setVisible(true); }
From source file:StylesExample5.java
public static void main(String[] args) { try {/*from w ww. j a va 2 s . com*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Styles Example 5"); // Create the StyleContext, the document and the pane StyleContext sc = new StyleContext(); final DefaultStyledDocument doc = new DefaultStyledDocument(sc); final JTextPane pane = new JTextPane(doc); // Create and add the style final Style heading2Style = sc.addStyle("Heading2", null); heading2Style.addAttribute(StyleConstants.Foreground, Color.red); heading2Style.addAttribute(StyleConstants.FontSize, new Integer(16)); heading2Style.addAttribute(StyleConstants.FontFamily, "serif"); heading2Style.addAttribute(StyleConstants.Bold, new Boolean(true)); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { try { // Add the text to the document doc.insertString(0, text, null); // Finally, apply the style to the heading doc.setParagraphAttributes(0, 1, heading2Style, false); // Set the foreground and font pane.setForeground(Color.blue); pane.setFont(new Font("serif", Font.PLAIN, 12)); } catch (BadLocationException e) { } } }); } catch (Exception e) { System.out.println("Exception when constructing document: " + e); System.exit(1); } f.getContentPane().add(new JScrollPane(pane)); f.setSize(400, 300); f.setVisible(true); }
From source file:BorderSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border bevelBorder = new BevelBorder(BevelBorder.RAISED, Color.red, Color.red.darker(), Color.pink, Color.pink.brighter()); Border emptyBorder = new EmptyBorder(5, 10, 5, 10); Border etchedBorder = new EtchedBorder(EtchedBorder.RAISED, Color.red, Color.pink); Border lineBorder = new LineBorder(Color.red, 5); Icon diamondIcon = new DiamondIcon(Color.red); Border matteBorder = new MatteBorder(5, 10, 5, 10, diamondIcon); Border softBevelBorder = new SoftBevelBorder(BevelBorder.RAISED, Color.red, Color.red.darker(), Color.pink, Color.pink.brighter()); Font font = new Font("Serif", Font.ITALIC, 12); Border titledBorder = new TitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM, font, Color.red);/*from ww w . j a v a2s .co m*/ Border compoundBorder = new CompoundBorder(lineBorder, matteBorder); JLabel bevelLabel = new JLabel("Bevel"); bevelLabel.setBorder(bevelBorder); bevelLabel.setHorizontalAlignment(JLabel.CENTER); JLabel emptyLabel = new JLabel("Empty"); emptyLabel.setBorder(emptyBorder); emptyLabel.setHorizontalAlignment(JLabel.CENTER); JLabel etchedLabel = new JLabel("Etched"); etchedLabel.setBorder(etchedBorder); etchedLabel.setHorizontalAlignment(JLabel.CENTER); JLabel lineLabel = new JLabel("Line"); lineLabel.setBorder(lineBorder); lineLabel.setHorizontalAlignment(JLabel.CENTER); JLabel matteLabel = new JLabel("Matte"); matteLabel.setBorder(matteBorder); matteLabel.setHorizontalAlignment(JLabel.CENTER); JLabel softBevelLabel = new JLabel("Soft Bevel"); softBevelLabel.setBorder(softBevelBorder); softBevelLabel.setHorizontalAlignment(JLabel.CENTER); JLabel titledLabel = new JLabel("Titled"); titledLabel.setBorder(titledBorder); titledLabel.setHorizontalAlignment(JLabel.CENTER); JLabel compoundLabel = new JLabel("Compound"); compoundLabel.setBorder(compoundBorder); compoundLabel.setHorizontalAlignment(JLabel.CENTER); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(2, 4, 5, 5)); contentPane.add(bevelLabel); contentPane.add(emptyLabel); contentPane.add(etchedLabel); contentPane.add(lineLabel); contentPane.add(matteLabel); contentPane.add(softBevelLabel); contentPane.add(titledLabel); contentPane.add(compoundLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:ComplexCellRenderer.java
public static void main(String args[]) { Object elements[][] = { { new Font("Helvetica", Font.PLAIN, 20), Color.RED, new MyIcon(), "A" }, { new Font("TimesRoman", Font.BOLD, 14), Color.BLUE, new MyIcon(), "A" }, { new Font("Courier", Font.ITALIC, 18), Color.GREEN, new MyIcon(), "A" }, { new Font("Helvetica", Font.BOLD | Font.ITALIC, 12), Color.GRAY, new MyIcon(), "A" }, { new Font("TimesRoman", Font.PLAIN, 32), Color.PINK, new MyIcon(), "A" }, { new Font("Courier", Font.BOLD, 16), Color.YELLOW, new MyIcon(), "A" }, { new Font("Helvetica", Font.ITALIC, 8), Color.DARK_GRAY, new MyIcon(), "A" } }; JFrame frame = new JFrame("Complex Renderer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ListCellRenderer renderer = new ComplexCellRenderer(); JComboBox comboBox = new JComboBox(elements); comboBox.setRenderer(renderer);/*from www . ja va 2 s .c o m*/ frame.add(comboBox, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:ComplexCellRenderer.java
public static void main(String args[]) { Object elements[][] = { { new Font("Helvetica", Font.PLAIN, 20), Color.RED, new MyIcon(), "A" }, { new Font("TimesRoman", Font.BOLD, 14), Color.BLUE, new MyIcon(), "A" }, { new Font("Courier", Font.ITALIC, 18), Color.GREEN, new MyIcon(), "A" }, { new Font("Helvetica", Font.BOLD | Font.ITALIC, 12), Color.GRAY, new MyIcon(), "A" }, { new Font("TimesRoman", Font.PLAIN, 32), Color.PINK, new MyIcon(), "A" }, { new Font("Courier", Font.BOLD, 16), Color.YELLOW, new MyIcon(), "A" }, { new Font("Helvetica", Font.ITALIC, 8), Color.DARK_GRAY, new MyIcon(), "A" } }; JFrame frame = new JFrame("Complex Renderer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist = new JList(elements); ListCellRenderer renderer = new ComplexCellRenderer(); jlist.setCellRenderer(renderer);// w w w.j a va 2s .c om JScrollPane scrollPane = new JScrollPane(jlist); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:ImageBouncer.java
public static void main(String[] args) { String filename = "java2sLogo.png"; if (args.length > 0) filename = args[0];//from w w w . j a v a2 s . co m Image image = null; try { image = blockingLoad(new URL(filename)); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } final ImageBouncer bouncer = new ImageBouncer(image); Frame f = new AnimationFrame(bouncer); f.setFont(new Font("Serif", Font.PLAIN, 12)); Panel controls = new Panel(); controls.add(bouncer.createCheckbox("Bilinear", ImageBouncer.BILINEAR)); controls.add(bouncer.createCheckbox("Transform", ImageBouncer.TRANSFORM)); final Choice typeChoice = new Choice(); typeChoice.add("TYPE_INT_RGB"); typeChoice.add("TYPE_INT_ARGB"); typeChoice.add("TYPE_INT_ARGB_PRE"); typeChoice.add("TYPE_3BYTE_BGR"); typeChoice.add("TYPE_BYTE_GRAY"); typeChoice.add("TYPE_USHORT_GRAY"); typeChoice.add("TYPE_USHORT_555_RGB"); typeChoice.add("TYPE_USHORT_565_RGB"); controls.add(typeChoice); f.add(controls, BorderLayout.NORTH); typeChoice.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ie) { String type = typeChoice.getSelectedItem(); bouncer.setImageType(type); } }); f.setSize(200, 200); f.setVisible(true); }