Set font on a text

Hi!
I've got some problem with setting font on a text, this is my coed:
var ar_delaney_e:Font = new ar_delaney();
textcount=1;
//Setting a variable to     ar_delaney_e
this["font_"+String(textcount)] = "ar_delaney_e";
//Create a textFormat
var textFormat:TextFormat = new TextFormat();
//Setting font textformat fon to ar_delaney_e??
textFormat.font = this["font_"+String(textcount)];
//Set textformat to my text
myText.defaultTextFormat = textFormat;
Fon is embedded hav also tried textFormat.font = this["font_"+String(textcount)].fontName; instead of textFormat.font = this["font_"+String(textcount)]; but no one of this will work, how can you fix this?

On stage I got a button with instance name add_text_btn, and a mc called "knapp_bild". So when pressing add_text_btn the function func_add_text_btn creates a movie clip with a text in it and also variables for size, color and font for the text. the two variables size and color works fine.
add_text_btn.addEventListener(MouseEvent.CLICK, func_add_text_btn);
function func_add_text_btn(event:MouseEvent):void{
textcount++;
var MovieClip:MovieClip = new MovieClip();
MovieClip.x = 80;
MovieClip.y = 60;
MovieClip.alpha = 1;
MovieClip.name="mc_text"+String(textcount);
//Variables for font, size and color
this["size_"+String(textcount)] = 40;
this["color_"+String(textcount)] = "0x00CC00";
this["font_"+String(textcount)] = "ar_delaney_e";
textFormat.font = this["font_"+String(textcount)].fontName;
textFormat.size = this["size_"+String(textcount)];
textFormat.color = this["color_"+String(textcount)];
var textField:TextField = new TextField()
textField.defaultTextFormat = textFormat;
textField.autoSize="left";
textField.text = 'Text '+String(textcount);
textField.name = "text"+String(textcount);  // give them names
textField.background=false;
textField.embedFonts=true;
var mc_name=String("mc_text"+String(textcount));
knapp_bild.addChild(MovieClip);
MovieClip.addChild(textField);
textField.mouseEnabled=false;
MovieClip.width=textField.width;
Later on in the program this["font_"+String(textcount)] will change but it dosen't work in the func_add_text_btn function now so let's just try to fix that first. Hope you can see something that mabe won't work and just ask if you got any qusetion. Thanks for your help!

Similar Messages

  • Setting Font for converting multiple text files into PDF using VB 6.0

    Dear All,
    Am converting multiple text files into PDF using VB6.0. Currently, am unable to control the font face and size for the generated files. Below is the procedure am using for each file;
    Public Sub proc_convert_to_PDF(srcFilename As String, destFilename As String)
    Dim p_AcroApp As CAcroApp
    Dim p_VDoc As CAcroAVDoc
    Dim p_DDoc As CAcroPDDoc
    Dim IsOk As Boolean
    Set p_AcroApp = CreateObject("AcroExch.App")
    Set p_VDoc = CreateObject("AcroExch.AVDoc")
    Call p_VDoc.Open(srcFilename, "")
    Set p_VDoc = p_AcroApp.GetActiveDoc
    If p_VDoc.IsValid Then
    Set p_DDoc = p_VDoc.GetPDDoc
    ' Fill in pdf properties.
    p_DDoc.SetInfo "Title", Format(Date, "dd-mm-yyy")
    p_DDoc.SetInfo "Subject", srcFilename
    If p_DDoc.Save(1 Or 4 Or 32, destFilename) <> True Then
    MsgBox "Failed to save " & srcFilename
    End If
    p_DDoc.Close
    End If
    'Close the PDF
    p_VDoc.Close True
    p_AcroApp.Exit
    'Clear Variables
    Set p_DDoc = Nothing
    Set p_VDoc = Nothing
    Set p_AcroApp = Nothing
    End Sub
    What I need;
    1) to be able to set the font face of the destination file ( destFilename)
    2) to be able to set the font size of the destination file ( destFilename)
    Am using Adobe Acrobat 7.0 Type Library
    Kindly Help.
    Thanks in advance

    We didn't say it doesn't work. We said it isn't supported.
    There are a number of other ways to make a PDF. The one which would
    give the most control is if your application directly printed to GDI,
    controlling the font directly. This could print to Adobe PDF.
    You could look for an application that gives control of font for
    printing.
    You could use a text-to-PostScript system and distill the result. You
    could even look for a non-Adobe text-to-PDF.
    Working in the unsupported and dangerous world you chose, the font
    size for text conversion is set (and this is very bad design from
    Adobe) in the settings for Create PDF > From Web Page. There is no API
    to this.
    Aandi Inston

  • Is there any easy & simple way to set specify font to all text

    Is there any way to set a specific font to all text of Swing controls (JLabel, JButton, etc)? And their font's style (bold, underscore...) and font's size still remain to their customized settings.
    Thanks in advance.
    null

    perhaps you're just after deriveFont()
    run this, you'll see both fonts the same
    import javax.swing.*;
    import java.awt.*;
    class Testing
      public void buildGUI()
        JLabel label_1 = new JLabel("Hello");
        JLabel label_2 = new JLabel("World");
        label_1.setFont(new Font("monospaced",Font.BOLD|Font.ITALIC,12));
        label_2.setFont(label_1.getFont());
        //label_1.setFont(label_1.getFont().deriveFont(36f));//<----------
        JFrame f = new JFrame();
        f.getContentPane().add(label_1,BorderLayout.NORTH);
        f.getContentPane().add(label_2,BorderLayout.SOUTH);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }now uncomment the indicated line, recompile/rerun
    you'll see the style remains, but the size increased

  • How do I change fonts in a Text field ??

    Okay I've tried to implement a JComboBox that allows the user to change fonts in the text field. So far I've tried different methods to do it but to no avail. Could somebodoy here read the programs source code for me and tell me where I went wrong?
    /* * My GUI Client */
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import javax.swing.event.*;
    //for HTML Headers
    import javax.swing.text.StyledEditorKit.*;
    import javax.swing.text.html.HTMLEditorKit.*;
    import javax.swing.text.html.*;
    import javax.swing.event.HyperlinkListener;
    import javax.swing.event.HyperlinkEvent;
    import javax.swing.event.HyperlinkEvent.EventType;
    import javax.swing.text.html.HTMLFrameHyperlinkEvent;
    //for layout managers
    import java.awt.event.*;
    //for action and window events
    import java.io.*;
    import java.net.*;
    import java.awt.GraphicsEnvironment;
    //for font settings
    import java.lang.Integer;
    import java.util.Vector;
    import java.awt.font.*;
    import java.awt.geom.*;
    public class guiClient extends JFrame implements ActionListener {
    protected static final String textFieldString = "JTextField";
    protected static final String loadgraphicString = "LoadGraphic";
    protected static final String connectString = "Connect";
    static JEditorPane editorPane;
    static JPanel layoutPanel = new JPanel(new BorderLayout());
    static JPanel controlPanel = new JPanel(new BorderLayout());
    static JPanel buttonPanel = new JPanel(new BorderLayout());
    static JPanel fontPanel = new JPanel(new BorderLayout());
    static PrintStream out;
    static DrawPanel dPanel;
    static DrawPanel dPButton;
    static DrawPanel dFonts;
    static DrawControls dControls;
    static DrawButtons dButtons;
    static String userString;
    static String currentFont;
    String fontchoice;
    String fontlist;
    static JTextField userName = new JTextField();
    public static JMenuBar menuBar;
    private static JButton connectbutton = new JButton("Connect");
    static boolean CONNECTFLAG = false;
    //create the gui interface
    public guiClient() {
         super("My Client");
    // Create a ComboBox
    GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String envfonts[] = gEnv.getAvailableFontFamilyNames();
    Vector vector = new Vector();
    for ( int i = 1; i < envfonts.length; i++ ) {
    vector.addElement(envfonts);
    JComboBox fontlist = new JComboBox (envfonts);
         fontlist.setSelectedIndex(0);
         fontlist.setEditable(true);
         fontlist.addActionListener(this);
         fontchoice = envfonts[0];     
    //Create a regular text field.
         JTextField textField = new JTextField(10);
         textField.setActionCommand(textFieldString);
         textField.addActionListener(this);          
    //Create an editor pane.
    editorPane = new JEditorPane();
         editorPane.setContentType("text");
         editorPane.setEditable(false);
    //set up HTML editor kit
         HTMLDocument m_doc = new HTMLDocument();
         editorPane.setDocument(m_doc);
         HTMLEditorKit hkit = new HTMLEditorKit();
         editorPane.setEditorKit( hkit );
         editorPane.addHyperlinkListener( new HyperListener());
    //Create whiteboard
    dPanel = new DrawPanel();
    dPButton = new DrawPanel();
    dFonts = new DrawPanel();
    dControls = new DrawControls(dPanel);
    dButtons = new DrawButtons(dPButton);
         //JLable fontLab = new JLabel(fontLable);
    //fontLab.setText("Fonts");
    //Font newFont = getFont().deriveFont(1);
    //fontLab.setFont(newFont);
    //fontLab.setHorizontalAlignment(JLabel.CENTER);
    JPanel whiteboard = new JPanel();
    whiteboard.setLayout(new BorderLayout());
    whiteboard.setPreferredSize(new Dimension(300,300));
    whiteboard.add("Center",dPanel);
    whiteboard.add("South",dControls);
    whiteboard.add("North",dButtons);
         JScrollPane editorScrollPane = new JScrollPane(editorPane);
         editorScrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
         editorScrollPane.setPreferredSize(new Dimension(250, 145));
         editorScrollPane.setMinimumSize(new Dimension(50, 50));
    //put everything in a panel
         JPanel contentPane = new JPanel();
         JPanel fontPane = new JPanel();
         contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    //add whiteboard
         contentPane.add(whiteboard);
    //add editor box
         contentPane.add(editorScrollPane);
    //add spacer
         contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    //add textfield
         contentPane.add(textField);
    //set up layout pane
         //layoutPanel.add(GridLayout(2,1),fontLab);
         layoutPanel.add( BorderLayout.NORTH, fontlist);     
         layoutPanel.add(BorderLayout.WEST,new Label("Name: ")); //add a label
         layoutPanel.add(BorderLayout.CENTER, userName ); //add textfield for user names
         layoutPanel.add(BorderLayout.SOUTH, connectbutton);//add dropdown box for fonts
         //fontPane.add(BorderLayout.NORTH,fontlist);
         contentPane.add(layoutPanel);
         contentPane.add(controlPanel);
         contentPane.add(buttonPanel);
    //Create the menu bar.
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    //Build the first menu.
         JMenu menu = new JMenu("File");
         menu.setMnemonic(KeyEvent.VK_F);
         menuBar.add(menu);
    //a group of JMenuItems
         JMenuItem menuItem = new JMenuItem("Load Graphic", KeyEvent.VK_L);
         menu.add(menuItem);
    menuItem.setActionCommand(loadgraphicString);
         menuItem.addActionListener(this);
    connectbutton.setActionCommand(connectString);
    connectbutton.addActionListener(this);
         setContentPane(contentPane);
    static private void insertTheHTML(JEditorPane editor, String html, int location) throws IOException {
         HTMLEditorKit kit = (HTMLEditorKit) editor.getEditorKit();
         Document doc = editor.getDocument();
         StringReader reader = new StringReader(html);
         try {
              kit.read(reader, doc, location);
         } catch (BadLocationException e) {}
    //listen for actions being performed and process them
    public void actionPerformed(ActionEvent e) {
    //if the action is from the textfield (e.g. user hits enter)
         if (e.getActionCommand().equals(textFieldString)) {
              JTextField fromUser = (JTextField)e.getSource();
         if (fromUser != null){
    //place user text in editor pane
    //send message to server
                   if (userName.getText() != null) {
                        userString = userName.getText().trim();
                   out.println(userString + ": " + fromUser.getText());
              fromUser.setText("");
         } else if(e.getActionCommand().equals(connectString)) {
              CONNECTFLAG = true;
    } else if (e.getActionCommand().equals(loadgraphicString) ) {
              final JFileChooser fc = new JFileChooser();
              int returnVal = fc.showOpenDialog(this);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
                   File file = fc.getSelectedFile();
                   dPanel.loadImage(file.getAbsolutePath());
                   sendImage(file);
         else if (e.getActionCommand().equals(fontlist)){
         JComboBox cb = (JComboBox)e.getSource();
    String newSelection = (String)cb.getSelectedItem();
    currentFont = newSelection;
         userString = currentFont;
    return;
    /*public void itemStateChanged (ItemEvent e) {
    if ( e.getStateChange() != ItemEvent.SELECTED ) {
    return;
    if ( list == fontlist ) {
    fontchoice = (String)fontlist.getSelectedItem();
         userString.changeFont(fontchoice);
    //append text to the editor pane and put it at the bottom
    public static void appendText(String text) {
         if (text.startsWith("ID ") ) {
              userString = text.substring(3);
         } else if (text.startsWith("DRAW ") ) {
              if (text.regionMatches(5,"LINE",0,4)) {
    dPanel.processLine(text);
         }else if (text.regionMatches(5,"POINTS",0,5)) {
         dPanel.processPoint(text);
         } else if (text.startsWith("IMAGE ") ) {
    int len = (new Integer( text.substring(6, text.indexOf(",")))).intValue();
    //get x and y coordinates
         byte[] data = new byte[ (int)len ];
         int read = 0;
    try {
         while (read < len) {
         data = text.getBytes( text.substring(0, len) );
    } catch (Exception e) {}
         Image theImage = null;
         theImage = dPanel.getToolkit().createImage(data);
         dPanel.getToolkit().prepareImage(theImage, -1, -1, dPanel);
         while ((dPanel.getToolkit().checkImage(theImage, -1, -1, dPanel) & dPanel.ALLBITS) == 0) {}
              dPanel.drawPicture(0, 0, theImage);
    } else {
    //set current position in editorPane to the end
              editorPane.setCaretPosition(editorPane.getDocument().getLength());
    //put text into the editorPane
              try {
                   insertTheHTML(editorPane, text, editorPane.getDocument().getLength());
              } catch (IOException e) {}
    } //end of appendText(String)
    public void sendImage(File file) {
    //find length of file
         long len = file.length();
    //read file into byte array
         byte[] byteArray = new byte[(int)len];
         try {
              FileInputStream fstream = new FileInputStream(file);
              if (fstream.read(byteArray) < len) {
    //error could not load file
              } else {
              out.println("IMAGE " + len + ",");
                   out.write(byteArray, 0, (int)len); //write file to stream
         } catch(Exception e){}
    //run the client
    public static void main(String[] args) {
         String ipAddr=null, portNr=null;
              if (args.length != 2) {
                   System.out.println("USAGE: java guiClient IP_Address port_number");
                   System.exit(0);
              } else {
         ipAddr = args[0];
              portNr = args[1];
              JFrame frame = new guiClient();
              frame.addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) { System.exit(0); }
              frame.pack();
              frame.setVisible(true);
              while(CONNECTFLAG == false){}
    //sames as previous client,
    //set up connection and then listen for messages from the Server
              String socketIP = ipAddr;
              int port = Integer.parseInt(portNr);
    //the IP address of the machine where the server is running
              Socket theSocket = null;
    //communication line to the server
              out = null;
    //for message sending
              BufferedReader in = null;
    //for message receiving
              try {
              theSocket = new Socket(socketIP, port );
    //try to connect
              out = new PrintStream(theSocket.getOutputStream());
                   dPanel.out = out;
    //for client to send messages
              in = new BufferedReader(new InputStreamReader(theSocket.getInputStream()));
                   BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in));
                   String fromServer;
                   while ((fromServer = in.readLine()) != null) {
                   appendText(fromServer);
                   if (fromServer.equals("BYE")) {
                        appendText("Connection Closed");
                        break;
              out.close();
    //close all streams
              in.close();
              theSocket.close();
    //close the socket
         } catch (UnknownHostException e) {
    //if the socket cannot be openned
              System.err.println("Cannot find " + socketIP);
              System.exit(1);
              } catch (IOException e) { //if the socket cannot be read or written
              System.err.println("Could not make I/O connection with " + socketIP);
              System.exit(1);
    class HyperListener implements HyperlinkListener {
    public JEditorPane sourcePane;
    public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
    sourcePane = (JEditorPane) e.getSource();
                   if (e instanceof HTMLFrameHyperlinkEvent) {
    HTMLFrameHyperlinkEvent event = (HTMLFrameHyperlinkEvent) e;
                        System.out.println(event.getTarget());
                        HTMLDocument doc = (HTMLDocument) sourcePane.getDocument();
                        doc.processHTMLFrameHyperlinkEvent(event);
    else {
    try {}
    catch (Exception ev){
         ev.printStackTrace();
    Well sorry the source code takes up the whole forum but I need a good feedback from this.

    All right...
    public class guiClient extends JFrame implements ActionListener {
    static String userString;
    static String currentFont;
    String fontchoice;
    String fontlist;
    static JTextField userName = new JTextField();
    public guiClient() {
         super("My Client");
    public guiClient() {
         super("My Client");
    // Create a ComboBox
    GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String envfonts[] = gEnv.getAvailableFontFamilyNames();
    Vector vector = new Vector();
    for ( int i = 1; i < envfonts.length; i++ ) {
    vector.addElement(envfonts);
    JComboBox fontlist = new JComboBox (envfonts);
         fontlist.setSelectedIndex(0);
         fontlist.setEditable(true);
         fontlist.addActionListener(this);
         fontchoice = envfonts[0];     
    //Create a regular text field.
         JTextField textField = new JTextField(10);
         textField.setActionCommand(textFieldString);
         textField.addActionListener(this);
    public void actionPerformed(ActionEvent e) {
    //if the action is from the textfield (e.g. user hits enter)
         if (e.getActionCommand().equals(textFieldString)) {
              JTextField fromUser = (JTextField)e.getSource();
         if (fromUser != null){
    //place user text in editor pane
    //send message to server
                   if (userName.getText() != null) {
                        userString = userName.getText().trim();
                   out.println(userString + ": " + fromUser.getText());
              fromUser.setText("");
         else if (e.getActionCommand().equals(fontlist)){
         JComboBox cb = (JComboBox)e.getSource();
    String newSelection = (String)cb.getSelectedItem();
    currentFont = newSelection;
         userString = currentFont;
    return;

  • Is there any way to change the default font for outgoing text-messages, in "Messages"? (OSX 10.10)

    Is there any way to change the default font for outgoing text-messages, in "Messages"?
    I can change it for one conversation, but then it resets to the default, tiny font.
    The preferences menu only lets me change the conversation font.
    (OSX 10.10)

    Hi,
    As you may remember there used to be a Messages pane to the Preferences where the Font and colour of the Balloons or background and the Font text colour could be changed.
    And there was a Format Menu for character, word and Sentence changes in the current IM or iMessage.
    Those have gone in Yosemite's version of Messages (Despite it retaining the designation of Messages 8 the same as Mavericks' version).
    All that can be done now is set the size of the font and this has been moved to the General Section of the Preferences.
    The Yosemite version has also been fixed to using the Balloons style of send and receiving any type of messages as well.
    Changing the Font would involved editing the Balloon.transcript file.
    10:34 pm      Saturday; December 13, 2014
    ​  iMac 2.5Ghz i5 2011 (Mavericks 10.9)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad

  • I created a pdf form from a Word doc with 9 pt aerial font formatting; the text on the pdf form is aerial 9 pt, but the fields are formatted in courier 12 pt - How do I reformat the font in the fields??

    I created a pdf form from a Word doc with 9 pt aerial font formatting; the text on the pdf form is aerial 9 pt, but the fields are formatted in courier 12 pt - How do I reformat the font in the fields??

    You can set up a temporary button (or link, bookmark, etc.) and add the following JavaScript action:
    // Mouse Up script for a temporary button (or bookmark, etc.)
    // Change the font and font size for all text fields in this document
    for (var i = 0; i < numFields; i += 1) {
        var f = getField(getNthFieldName(i));
        if (f.type === "text") {
            f.textFont = font.Helv;
            f.textSize = 9;
    It also sets the font size, but you can remove that line if you don't need to do that.

  • Setting Font Color and Bold Property in ALV Grid

    I have a requirement to set the font in particular ALV Cells  in red color.
    Also this font (text) has to be set to Bold.
    I know how to set cell coloring in ALV Grid, but have no idea regarding how to set font color.
    Could please give me an idea/code segment/suggestion.
    Thank You!

    Please refer this post
    Coloring of ROWS in ALV tree

  • How do I make mail readable, text barely readable on screen when set to 12 point text.

    Is there a way to increase the size of the displayed mail, as you are creating it?
    I have mine set to 12 point text, but it is still difficult to read. The e-mail when received is fine, it's the creating that's "tiny"
    Thanks
    Mike

    I use "screen zoom" (control + scroll up/down) often when creating these responses.  Or for anything else where I do not want to change the number of open winodws.
    You can also write the message in 16 pt font and "select all" to make it 12-point before sending.

  • Setting fonts in reports.

    Using labview V6.1 and Windows 2000.
    I am using the Append front panel image to report.vi to attach a panel image to a report. I would like to set the font of the text that is in this image, but the set report font.vi does nothing for this neither does setting the font in the vi I wish to append.
    any ideas?

    send you code please i will try to do it

  • Bullet Using Different Font than Body Text

    I would like to have a bullet that uses a different font than the body text. Say, for text I use Verdana, and for the bullet I would like to use a glyph from Zapf Dingbats. I seem to not be able to figure out how to set this up -- the bullet always uses the same font as the text.
    Thanks for your help.
    -- Stefan

    If you Option-Click on the bullet character, you can select it on its own, separate from the body text. You can then apply whatever font you want, and in the Text Inspector, in the Bullets palette, you can type whatever character you want in the Text Bullets field. (If you want this character for all of your bullets, it would be easiest to do this editing on the slide masters, rather than the individual slides.)

  • Set font size based on component size

    Hi everybody,
    This is kind of a duplicate, kind of new, because my original post is buried and I figured out a more helpful and general way to ask this question. Does anyone know if there is a way to set the size of a string as large as possible on a component, but still be able to have the whole string visible, if you're using a font other than default?
    For example:
    public static void main( String args[] ){
    try {
              JFrame frame = new JFrame( "Title" );
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              int guiWidth = width / 2;
              int guiHeight = height / 2;
              frame.setSize( guiWidth, guiHeight );
              Container pane = frame.getContentPane();
              // Create main label
              String labelString = "Test";
              JLabel label = new JLabel( labelString );
              label.setBackground( new Color( 179, 0, 0 ) );
              label.setForeground( new Color( 235, 191, 16 ) );
              label.setHorizontalAlignment( CENTER );
              label.setOpaque( true );
              label.setFont( new Font( �Old English Text MT�, 0, 48 ) );
              pane.add( label, BorderLayout.NORTH );
              frame.setLocationRelativeTo( null );
              frame.setVisible( true );
    } catch( Exception e) {
    e.printStackTrace();
         }As you can see, right now the font needs to be hard coded. I'd like it to be dynamic, based on the size of the screen the user has.
    Sorry if the partial double post annoys anybody; I figured it would be less annoying than resurrecting my old post.
    Any help on this would be great, and thank you!
    Jezzica85
    Message was edited by:
    jezzica85
    Message was edited by:
    jezzica85

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.font.*;
    import java.awt.geom.AffineTransform;
    import javax.swing.*;
    public class DynamicFont {
        private JLabel getNorth() {
            // Create main label
            String labelString = "Test";
            final JLabel label = new JLabel( labelString ) {
                public void paint(Graphics g) {
                    ((Graphics2D)g).setRenderingHint(
                            RenderingHints.KEY_TEXT_ANTIALIASING,
                            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                    super.paint(g);
            label.setBackground( new Color( 179, 0, 0 ) );
            label.setForeground( new Color( 235, 191, 16 ) );
            label.setHorizontalAlignment( JLabel.CENTER );
            label.setOpaque( true );
            label.setFont( new Font( "Old English Text MT", 0, 48 ) );
            label.addComponentListener(new ComponentAdapter() {
                Font font = label.getFont();
                public void componentResized(ComponentEvent e) {
                    int w = label.getWidth();
                    int sw = label.getFontMetrics(font).stringWidth(label.getText());
                    double scale = (double)w/sw;
                    AffineTransform at = AffineTransform.getScaleInstance(scale, 1.0);
                    label.setFont(font.deriveFont(at));
                    label.repaint();
            return label;
        public static void main( String[] args ) {
            JFrame frame = new JFrame( "Title" );
            frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
            Container pane = frame.getContentPane();
            pane.add( new DynamicFont().getNorth(), BorderLayout.NORTH );
            frame.setSize( 400, 100);
            frame.setLocationRelativeTo( null );
            frame.setVisible( true );
    }

  • Setting font and color TextItems

    This script is failing to set font, and how can I set font color?; I am new to PS Scripting:
         var originalUnit = preferences.rulerUnits
          preferences.rulerUnits = Units.INCHES
         var docRef = app.documents.add( 11, 17, 300, "Test", NewDocumentMode.CMYK)
        MyLayer = docRef.artLayers.add()
         MyLayer.kind = LayerKind.TEXT
         var myFont = app.fonts.getByName("ArialMT");
         // Set the contents of the text layer.
         var textItemRef = MyLayer.textItem
         textItemRef.font = myFont;
         textItemRef.size = UnitValue(36, 'pt');
         textItemRef.font = '_Aviano-Regular';
         textItemRef.style = "Italic";
         textItemRef.contents = "Sample Text";
         // Restore original ruler unit setting
          app.preferences.rulerUnits = originalUnit
    Thanks

    The font needs to be the postscript name, this will give you a list of them.
    var Dlog =
    "dialog{text:'Script Interface',bounds:[100,100,500,270],"+
    "FontName:DropDownList{bounds:[30,40,370,60]},"+
    "PostScriptName:DropDownList{bounds:[30,100,370,120]},"+
    "statictext0:StaticText{bounds:[40,10,200,30] , text:'Font Name'},"+
    "statictext1:StaticText{bounds:[40,70,141,87] , text:'Postscript Name'},"+
    "button0:Button{bounds:[140,130,240,150] , text:'Ok' }}";
    win = new Window(Dlog,"Use the Postscript Name in your script.");
    var item;
    var item2;
    for (var i=0,len=app.fonts.length;i<len;i++) {
      item = win.FontName.add ('item', "" + app.fonts[i].name);
      item2 = win.PostScriptName.add ('item', "" + app.fonts[i].postScriptName);   
    win.FontName.selection = win.FontName.items[0] ;
    win.PostScriptName.selection = win.PostScriptName.items[0] ;
    win.FontName.onChange = function() {
    win.PostScriptName.selection = win.PostScriptName.items[parseInt(this.selection)] ;
    $.writeln(win.PostScriptName.items[parseInt(this.selection)]);
    win.PostScriptName.onChange = function() {
    win.FontName.selection = win.FontName.items[parseInt(this.selection)] ;
    win.center();
    win.show();
    Here is your code with colour addded...
         var originalUnit = preferences.rulerUnits
          preferences.rulerUnits = Units.INCHES
          var FillColor = new SolidColor;
        FillColor.rgb.hexValue = 'ff0000';
         var docRef = app.documents.add( 11, 17, 300, "Test", NewDocumentMode.CMYK)
        MyLayer = docRef.artLayers.add()
         MyLayer.kind = LayerKind.TEXT
         var myFont = "ArialMT";
         // Set the contents of the text layer.
         var textItemRef = MyLayer.textItem
         textItemRef.font = myFont;
         textItemRef.size = UnitValue(36, 'pt');
         textItemRef.font = myFont;
         //textItemRef.style = "Italic";
         textItemRef.fauxItalic = true;
         textItemRef.contents = "Sample Text";
         textItemRef.color = FillColor;
         // Restore original ruler unit setting
          app.preferences.rulerUnits = originalUnit

  • How to set Font in JEditorPane

    i have problem set Font in JEditorPane.please help how to set Font in JEditorPane.
    My Code,
    JEditorPane view = new JEditorPane();
    view.setEditable(false);
    view.setContentType("text/html");
    JScrollPane scroll = new JScrollPane(view);
    scroll.setMinimumSize(new java.awt.Dimension(50, 50));
    scroll.setPreferredSize(new java.awt.Dimension(450, 300));
    scroll.setAutoscrolls(true);
    scroll.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scroll.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    view.setBorder(null);
    view.setFont(new java.awt.Font("Monospaced", 0, 12));
    view.setDragEnabled(true);
    view.setMargin(new java.awt.Insets(10, 10, 10, 10));
    view.setMinimumSize(new java.awt.Dimension(100, 20));
    view.setPreferredSize(new java.awt.Dimension(450, 300));

    Have a look at SimpleAttributeSet.

  • Splitting of text fields when using multiple fonts within a text field and exporting it to XFL.

    Hi All,
    I have been trying out  InDesign and exported files to XFL for use in Flash. If I use a single font for a text box then everything looks fine in flash, but if  I use multiple fonts for the same text box its split into multiple text boxes. For making this more clear I have attached an image.
    Any help to resolve this!!!

    Paragraph styles are tied to the paragraph, not the page.
    You don't say which version you are using, but here's something you could try in CS3 or CS4. Set up a baseline grid in the preferences to match the main pages. The spacing should match the leading of the body text. Make a special paragraph style (you can base it on the body text style) that you will apply to text onthe chapter start page, and as part of that style set it to align to baseline grid. Now for the trick. Select the  text frame onthe start page and define a custom baseline grid with the spacing you want. Save it as an object style, too, while you're at it. The strating text should align to the custom grid on the start page and the documetn grid on the next page.
    Peter

  • Unable to apply embedded font swf to text in text layout framework

    Hello,
    We have created a swf for a given font (for e.g., Calibri.swf) which contains all the styles (Regular, Italic, Bold, BoldItalic).
    We have created a xml which lists the name of the font and the corresponding swf file path. The names from the xml are loaded into a combo box in the application.
    When we try to apply the selected font to a text in the text layout framework, it does not apply the same. It sets the font to default "Times" font.
    Following is a snippet of code to apply the font to the text:
    private function selectFont(fontXML:XML):void {               
                    var path:String = fontXML.@source;
                    var myEvent:IEventDispatcher = styleManager.loadStyleDeclarations(FlexGlobals.topLevelApplication.url.substring(0,FlexGl obals.topLevelApplication.url.lastIndexOf("/"))+"/"+path);
                    myEvent.addEventListener(StyleEvent.COMPLETE, function(event:StyleEvent):void{
                        var editManager:EditManager = textFlow.interactionManager as EditManager;
                        var itextLayout:TextLayoutFormat = new TextLayoutFormat();
                        itextLayout.fontSize = 20;
                        var fontName:String = fontXML.@name;
                        Alert.show(fontName);
                        itextLayout.fontFamily = fontName;   
                        Alert.show( "itext = " + itextLayout.fontFamily);
                        editManager.applyFormat(itextLayout,itextLayout,itextLayout);
                        var flowLeafElement:FlowElement = textFlow.findLeaf(editManager.anchorPosition) as FlowElement;
                        editManager.changeStyleName(fontName,flowLeafElement);
    Can anyone please let us know what is missing in the implementation?
    Thanks in advance.
    Vikram

    My recommendation: unless you really care about ISWFContext implementations and the application domain issues, ignore Alex's post about embedded fonts.
    It is a nice discussion about the inner workings of the domain and security of how this works but it is imho broken and is an insane concept to require an ISWFContext to just use an embedded font. It also breaks runtime CSS loading that has fonts embedded in it because the Flex compiler (last I checked) was also busted – it doesn't include the function necessary to create within context the font embed so that it may be applied. You can't create an ISWFContext with a compiled CSS file.
    These issues were introduced in the last Flex SDK beta before FB4 was released in final form. There are multiple bugs logged against the issue of applying loaded font files to TLF text (in short, SWFContext is broken and you have to override GlobalSettings.resolveFontLookupFunction to return embedded or null, all the time).
    Here's some more details to get you started - with links to at least one of the SDK bugs that were filed:
    http://forums.adobe.com/message/2656152
    For example:
    import flashx.textLayout.elements.GlobalSettings;
    import flash.text.engine.FontLookup;
    GlobalSettings.resolveFontLookupFunction = function makeValid():String { return FontLookup.EMBEDDED_CFF };
    And you may need to do this after your font is loaded:
    yourTextBlock.textFlow.invalidateAllFormats();
    Disclaimer: I haven't seen the latest Flex SDK release to see if this was fixed. I have an AIR application with native process that builds embedded font SWF files for use and stub code for FB4 usage but haven't updated to the latest SDK yet to see if it's working properly.
    Anyhow, your best bet is to look at the Flash Builder forums. I think this is/was a Flex team issue, not TLF.

Maybe you are looking for

  • Imac no longer charging via usb

    27" iMac Intel Core i5 OS X (10.6.7) So plugged in the ipod (via usb to the back of the imac) and left it to charge overnight. The next morning I notice it is not showing up in Itunes, and lo and behold has not charged a lick! So I thought it was the

  • Snow Leopard Installer does not recognize Hard drive in disk utility.

    I first at the suggestion of apple technicians because of other problems erased and partitioned hard drive. Now when I go to reinstall Snow Leopard it does not recognize the Macintosh Hard Drive, not even in disk utility. Any help will be greatly app

  • Is it possible for me to get separate bills for everyone on my line?

    Is it at all possible that I can get separate bills sent to different addresses for the people on my line?

  • 2011 macbook pro cannot turn on

    Hello everyone. After I replaced my MBP's hard disk with a SSD, it cannot turn on. There is no reaction when I press the power button. The 6th light of the battery indicator (side) is green and is always on. There's no change of the indicator lights

  • USB key keep connecting and disconnecting

    Hello, I've recently bought a Satellite L655D-12P computer and I have a Sony USB key ( USM8GL). The issue is that my key connects itself to the PC, then disconnects, reconnects etc... and keep doing the same thing indefinitely every 5 seconds. I don'