Change font with a bottom.

Hi,
I couldn't find an answer for this but: Is there a way to chnage the font in the front panel by pressing a button?
As you can see, I am building a farily simple starwars-theme-application, what I want to to is to use that funky starwar font ( like the one os top of the siganl inputs), but when a button is press the font goes back to a readable font (ie; arial)
Solved!
Go to Solution.

You can create a property node for each of the controls you want to change.  Write the font name to the property Label.FontName.

Similar Messages

  • Can I change Fonts with Dragon Dictate

    Can I Change Fonts, Call out e-mail and search Commands with Dragon Dictate ?
    Also Can I use it without a Head Phone because my Speakers etc. plug in that portion
    behind the screen.

    Speech recognition expert Dan Newman of Sayican.com has a training video for Dragon Dictate. There is a free lesson that you can download.

  • CHANGE  FONT WITH JTEXTPANE

    I am using JTextPane and want the user to be able to highlight text and change font styles. How do I do this? I tried setFont but it does not work. Thanks.. Sarah

    Hello,
    did you try something like this :
    javax.swing.text.MutableAttributeSet attr = new javax.swing.text.SimpleAttributeSet();
    attr.addAttribute(javax.swing.text.StyleConstants.FontFamily, fontName);
    yourJTextPane.getStyledDocument().setCharacterAttributes(yourJTextPane.getSelectionStart(), yourJTextPane.getSelectionEnd() - yourJTextPane.getSelectionStart(), attr, false);

  • Changing Fonts with a Pre-made Template

    I am trying to change the font of the words in the premade template titled "Float." Is this even a possibility? I am having a hard time figuring it out.
    Thanks for any help.

    it's all grouped according to the dropzone...hit f5 and in your layers tab, right before the name of the group is a little arrow, click it to reveal 3 other groups, repeat the process till you see the text layer.... New to motion? Read the manual and do the tutorials.

  • Cannot quick change font with arrow key / mac

    I have been using illustrator for years on windows and just recently switched to mac.
    On the windows version of Illustrator CS5 you can preview different fonts on the desired text by just placing the cursor on the font selection bar and then simply press the up/down arrows keys. On mac it does not work that way.
    Does anybody know how i can fix this?

    I'm having the same issue on:
    PC
    Windows 7
    Adobe Illustrator CS5
    Also, at certain times I click in the font selection bar and type in the name of the font I want... or part of it and it shows up and when I hit the enter key it does not change the font but rather switches the selected font back to what it was originally on. Effectively doing nothing.

  • Motion project to Compressor - changes font with render

    I have a project that is a simple opening title using Frutiger Black Condensed as the font (isn't everyone using Frutiger today?)
    The font is not in my user folder. It's located in the main Library Font folder. I had this issue before and it was because the font was in the User folder. You guys helped me with that one!
    The font has been validated.
    There are no duplicates.
    Motion sees the font and lets me set text to the font.
    I export it to Compressor and the Preview in Compressor shows the correct font.
    I render it using the Animation codec and the resulting QT movie has a different font.
    Rendering directly out of Motion works fine, of course, but I want to use Compressor because I want to set up several to render and walk away.
    Thanks for any help or tips.
    Scot
    Message was edited by: Scot Walker

    how very strange I had exactly the same issue today. The .mp4 export via compressor from motion had a substituted font. I didnt have too much time to explore the situation.
    the work around for me was to bring the motion project into fcp and then export it via compressor from there. Why this should be different I have no idea, but it worked.
    thanks
    adam

  • [SOLVED]Change font issue

    Hi, im new to Arch , im happy with it so far! But I want to get my favorite font "terminus" to work. I've read the wiki and i've also checked the FAQ for urxvt how to change font with no success. Im using latest Arch and I use urxvt as my terminal and awesome as wm, and i want the font to work on those both and in luakit if its possible. I've setup my xinitrc to make terminus work i've also resintalled it ones cuz I thought the font was broken or something. I used "URxvt.font:terminus" in my $HOME/.Xdefaults with no success. Ive also tried to add it to my rc.conf but it didnt make the font work in X(i havent checked if it appears on the commandline with no X up and running).
    I hope i could get some help
    Last edited by GNUkid (2012-03-11 18:36:38)

    karol wrote:
    urxvt*font: -*-terminus-medium-r-*-*-12-*-*-*-*-*-*-*
    works for me.
    Post your .Xdefaults.
    Didnt work Heres my .Xdefualts:
    urxvt*font: -*-terminus-medium-r-*-*-12-*-*-*-*-*-*-*
    URxvt.foreground: #1793D1
    URxvt.background: #555753
    URxvt.scrollBar: off
    magicalChicken wrote:
    .Xdefaults is deprecated, use .Xresources instead. Try in .Xresources adding
    urxvt*font: <name of font>
    Then to your .xinitrc add
    xrdb --merge ~/.Xresources
    I use this for setting the inconsolata font as default in urxvt and it works just fine.
    The .Xresources didnt work for me for some reason so thats why im using Xdefaults.

  • Easiest way to change font size/color with CSS?

    I've never used CSS before; I need to know how to change the font size and color using CSS, since it seems to be the only way to do it now. Sometimes I just need to change the font just for a few words, or a line here and there. Not necessarily page-wide, you understand. Is there a step-by-step process showing the simplest way to accomplish this? I'm not a web developer or professional designer, nor do I want to be. I just use DW to build simple web sites for personal use. I don't build using HTML - I solely use DM's GUI functions. And I'm also trying to teach my nine year-old how to start out page-building. I certainly hope that something as simple as changing font size doesn't require one to buy a book to learn HTML, which seems to be what a lot of people are telling me. Thanks for any assistance.

    Easiest is not always the best way.  You must learn the fundamentals. 
    CSS
    /**this styles all paragraphs in your site**/
    p {
    font-size: 18px;
    color: #000;
    /**This is a class.  Classes are re-usable**/
    .red {
    color:red;
    font-weight:bold;
    HTML:
    <p>This is a normal paragraph</p>
    <p class="red">This is a red paragraph</p>
    <p>This is a normal paragraph with <span class="red">some red text here</span> but not here.</p>
    If you're going to teach your 9yr old how to build web pages, start with the links below.
    There's no point in teaching your child bad habits that will have to be unlearned later.
    http://www.html.net/
    http://w3schools.com/
    http://www.csstutorial.net/
    http://phrogz.net/css/HowToDevelopWithCSS.html
    Nancy O.

  • I'm using firefox 6.0.2 It's making problem with Bangla font ONLY on FACEBOOK others bangli website FORNT SIZE are OK. On the FACEBOOK it shows Bangla font in a very / Too small! I change font SIZE in firefox setting but i can't solve. Pls HELP me

    I'm using firefox 6.0.2 It's making problem with Bangla font ONLY on FACEBOOK others bangli website FORNT SIZE are OK. On the FACEBOOK it shows Bangla font in a very / Too small! I change font SIZE in firefox setting but i can't solve. Pls HELP me ..

    Reset the page zoom on pages that cause problems: <b>View > Zoom > Reset</b> (Ctrl+0 (zero); Cmd+0 on Mac)
    *http://kb.mozillazine.org/Zoom_text_of_web_pages
    You can use an extension to set a default font size and page zoom on web pages.
    *Default FullZoom Level: https://addons.mozilla.org/firefox/addon/default-fullzoom-level/
    *NoSquint: https://addons.mozilla.org/firefox/addon/nosquint/

  • Office365 macbook air while copy paste and change font to tahoma forarded message remain with different fonts and size not accepting change

    office365 macbook air while copy paste and change font to tahoma forarded message remain with different fonts and size not accepting change
    mac yosemite
    office365

    Also here's the log before it happened. As you can see there is no activity from 9:48 to 10:00 am when the sound occurred.
    23/02/2014 9:48:12.792 am ntpd[52]: FREQ state ignoring -0.145411 s
    23/02/2014 9:48:15.258 am WindowServer[96]: _CGXHWCaptureWindowList: No capable active display found.
    23/02/2014 9:48:20.000 am kernel[0]: AppleCamIn::systemWakeCall - messageType = 0xE0000280
    23/02/2014 9:48:20.000 am kernel[0]: ARPT: 61.319378: AirPort_Brcm43xx::powerChange: System Sleep
    23/02/2014 9:48:20.000 am kernel[0]: ARPT: 61.319390: wl0: powerChange: *** BONJOUR/MDNS OFFLOADS ARE NOT RUNNING.
    23/02/2014 9:48:20.000 am kernel[0]: AppleCamIn::systemWakeCall - messageType = 0xE0000340
    23/02/2014 10:00:04.000 am bootlog[0]: BOOT_TIME 1393167604 0
    23/02/2014 10:00:06.000 am syslogd[17]: Configuration Notice:
    ASL Module "com.apple.appstore" claims selected messages.
    Those messages may not appear in standard system log files or in the ASL database.
    23/02/2014 10:00:06.000 am syslogd[17]: Configuration Notice:
    ASL Module "com.apple.authd" sharing output destination "/var/log/system.log" with ASL Module "com.apple.asl".
    Output parameters from ASL Module "com.apple.asl" override any specified in ASL Module "com.apple.authd".

  • Changing fonts and font sizes with hotkeys

    In MS Word you can select text and hit Ctrl + Shift + "F" to get to the drop down menu to change the font and just hit tap to change the size. Is that possible in Pages?

    Use cmd shift + or - to change font size.
    It may be cmd - for the reduce size, I may have regularised the keyboard shortcut on my system.
    You will need to use the toolbar or the type palette to change the font itself.
    Peter
    btw Once you are in the various pulldown menus, including the toolbar Type menus, you can use your up or down keys plus enter or return to change selections.

  • How do I change font in Firefox example when I go to Craigs list, everything is in italics....not so with Internet Explorer....I like Mozilla best and want to correct this problem

    How do I change fonts in Mozilla"

    Hi,
    Please try this: '''Tools''' (or '''Alt''' + '''T''') > '''Options''' > '''Applications'''. Look for or start typing '''mailto''' in the search box and for the '''Action''' change it to the desired mail client (the application that opens up in Explorer) if the value is different.
    '''Options''' > '''Applications''': https://support.mozilla.com/en-US/kb/Options%20window%20-%20Applications%20panel
    Managing Actions: https://support.mozilla.com/en-US/kb/Managing%20file%20types

  • 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;

  • Embedded fonts with rich editable text

    Hi, I am trying to use my embedded fonts in rich editable text field, but it only works for users that already have that font installed on their system.
    This is what I do.
    I embed fonts like this:
         @font-face {
                src:url("fonts/Cantarell-Regular.ttf");
                fontFamily: Cantarell;
                advancedAntiAliasing: true;
            @font-face {
                src:url("fonts/Cantarell-Bold.ttf");
                fontFamily: Cantarell;
                fontWeight: bold;
                advancedAntiAliasing: true;
    Then in my DropDownList (id=fontPicker) I add a new string entry that references my new font (in this case "Cantarell")
    I have a custom item renderer which makes sure to print out the name of the font using the font itself, so that for example font name "Cantarell" will be printed out using Cantarell font. Code in my custom font item renderer looks like this:
    <s:Label id="labelDisplay"
                 fontFamily="{data}"
                 verticalCenter="0"
                 left="3" right="3" top="6" bottom="4"/>
    And this part works, even if you dont have the font installed on your system, the name of the font is displayed propperly.
    The thing that I want to do is to select some text in my rich editable text field and change the font of the selected text depending on what user selected from the dropdownlist. I added an event which is called once user selects new font type, and it performs following code on the selection in rich editable text:
                   if(fontPicker.selectedIndex == -1){
                        //user did not select anything, we do not change the font
                        text.setFocus();
                        return;
                   //we get the text layout format of the selected text
                    var txtLayFmt:TextLayoutFormat = text.getFormatOfRange(null,text.selectionAnchorPosition,text.selectionActivePosition);
                   //we change fontFamily of the selected text to the font that we just picked
                    txtLayFmt.fontFamily = fontPicker.selectedItem;
                    // I even tryed to add those two following lines without much help
                    //txtLayFmt.fontLookup = FontLookup.EMBEDDED_CFF;
                    //txtLayFmt.renderingMode = RenderingMode.CFF;
                   // we update our selected text with new font
                    text.setFormatOfRange(txtLayFmt,text.selectionAnchorPosition,text.selectionActivePosition );
                    text.setFocus();
    This code works perfect if user has the font installed on their system but it does not work if they dont have the font even if I embed the font.
    What I am doing wrong, any suggestions, tips, links?
    Thanks,
    Dal

    Thanks I will take a look at your blogs, maybe I find some explanations.
    Once it comes to my problem, I found a solution, I just needed to add a simple style:
            .mystyle1 {
                 fontFamily:Cantarell;
    and set the styleName of my text to it:
    text.styleName = "mystyle1";
    Afterwards I can dynamically change fonts and sizes of the text selections in my rich editable text field as much as I like.
    Also I need to make sure that I set embed-as-cff: true;
          @font-face {
                src:url("fonts/Cantarell-Bold.ttf");
                fontFamily: Cantarell;
                fontWeight: bold;
                advancedAntiAliasing: true;
                embed-as-cff: true;
    I hope this helps someone.
    And if anyone has explanation to why embedded fonts work only after I change styleName of a text to a random style, please share with me.
    Cheers,
    Dal.

  • How to change font/ font color etc in a graphic object using JCombobox?

    Hello
    My program im writing recently is a small tiny application which can change fonts, font sizes, font colors and background color of the graphics object containing some strings. Im planning to use Jcomboboxes for all those 4 ideas in implementing those functions. Somehow it doesnt work! Any help would be grateful.
    So currently what ive done so far is that: Im using two classes to implement the whole program. One class is the main class which contains the GUI with its components (Jcomboboxes etc..) and the other class is a class extending JPanel which does all the drawing. Therefore it contains a graphics object in that class which draws the string. However what i want it to do is using jcombobox which should contain alit of all fonts available/ font sizes/ colors etc. When i scroll through the lists and click the one item i want - the graphics object properties (font sizes/ color etc) should change as a result.
    What ive gt so far is implemented the jcomboboxes in place. Problem is i cant get the font to change once selecting an item form it.
    Another problem is that to set the color of font - i need to use it with a graphics object in the paintcomponent method. In this case i dnt want to create several diff paint.. method with different property settings (font/ size/ color)
    Below is my code; perhaps you'll understand more looking at code.
    public class main...
    Color[] Colors = {Color.BLUE, Color.RED, Color.GREEN};
            ColorList = new JComboBox(Colors);
    ColorList.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ev) {
                     JComboBox cb = (JComboBox)ev.getSource();
                    Color colorType = (Color)cb.getSelectedItem();
                    drawingBoard.setBackground(colorType);
              });;1) providing the GUI is correctly implemented with components
    2) Combobox stores the colors in an array
    3) ActionListener should do following job: (but cant get it right - that is where my problem is)
    - once selected the item (color/ font size etc... as i would have similar methods for each) i want, it should pass the item into the drawingboard class (JPanel) and then this class should do the job.
    public class DrawingBoard extends JPanel {
           private String message;
           public DrawingBoard() {
                  setBackground(Color.white);
                  Font font = new Font("Serif", Font.PLAIN, fontSize);
                  setFont(font);
                  message = "";
           public void setMessage(String m) {
                message = m;
                repaint();
           public void paintComponent(Graphics g) {
                  super.paintComponent(g);
                  //setBackground(Color.RED);
                  Graphics2D g2 = (Graphics2D) g;
                  g2.setRenderingHint             
                  g2.drawString(message, 50, 50);
           public void settingFont(String font) {
                //not sure how to implement this?                          //Jcombobox should pass an item to this
                                   //it should match against all known fonts in system then set that font to the graphics
          private void settingFontSize(Graphics g, int f) {
                         //same probelm with above..              
          public void setBackgroundColor(Color c) {
               setBackground(c);
               repaint(); // still not sure if this done corretly.
          public void setFontColor(Color c) {
                    //not sure how to do this part aswell.
                   //i know a method " g.setColor(c)" exist but i need to use a graphics object - and to do that i need to pass it in (then it will cause some confusion in the main class (previous code)
           My problems have been highlighted in the comments of code above.
    Any help will be much appreciated thanks!!!

    It is the completely correct code
    I hope that's what you need
    Just put DrawingBoard into JFrame and run
    Good luck!
    public class DrawingBoard extends JPanel implements ActionListener{
         private String message = "message";
         private Font font = new Font("Serif", Font.PLAIN, 10);
         private Color color = Color.RED;
         private Color bg = Color.WHITE;
         private int size = 10;
         public DrawingBoard(){
              JComboBox cbFont = new JComboBox(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
              cbFont.setActionCommand("font");
              JComboBox cbSize = new JComboBox(new Integer[]{new Integer(14), new Integer(13)});
              cbSize.setActionCommand("size");
              JComboBox cbColor = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbColor.setActionCommand("color");
              JComboBox cbBG = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbBG.setActionCommand("bg");
              add(cbFont);
              cbFont.addActionListener(this);
              add(cbSize);
              cbSize.addActionListener(this);
              add(cbColor);
              cbColor.addActionListener(this);
              add(cbBG);
              cbBG.addActionListener(this);
         public void setMessage(String m){
              message = m;
              repaint();
         protected void paintComponent(Graphics g){
              super.paintComponent(g);
              Graphics2D g2 = (Graphics2D)g;
              g2.setColor(bg);//set background color
              g2.fillRect(0,0, getWidth(), getHeight());          
              g2.setColor(color);//set text color
              FontRenderContext frc = g2.getFontRenderContext();
              TextLayout tl = new TextLayout(message,font,frc);//set font and message
              AffineTransform at = new AffineTransform();
              at.setToTranslation(getWidth()/2-tl.getBounds().getWidth()/2,
                        getWidth()/2 + tl.getBounds().getHeight()/2);//set text at center of panel
              g2.fill(tl.getOutline(at));
         public void actionPerformed(ActionEvent e){
              JComboBox cb = (JComboBox)e.getSource();
              if (e.getActionCommand().equals("font")){
                   font = new Font(cb.getSelectedItem().toString(), Font.PLAIN, size);
              }else if (e.getActionCommand().equals("size")){
                   size = ((Integer)cb.getSelectedItem()).intValue();
              }else if (e.getActionCommand().equals("color")){
                   color = (Color)cb.getSelectedItem();
              }else if (e.getActionCommand().equals("bg")){
                   bg = (Color)cb.getSelectedItem();
              repaint();
    }

Maybe you are looking for