Set Font to the JTextArea Problem

Hi all, i've got a problem in setting the font for my JTextArea.
Here is my piece of code.
Display.append(Message.getText());
Display.setFont(selected_font));
Display is JTextArea, Message is String.
The problem is i whenever i do this, everytime i change the Font of the Message, the whole messages in the Display font also change.
What i want is, when i change the font of certain message, that certain message font ( instead of all message) also change in the Display.
I know the problem is because of the Display.setFont(), it set the font for the whole content inside the Display. Any help to fulfill what i want?

I'm not sure a JTextArea is appropriate for what you're doing. As its API documentation begins by saying "A JTextArea is a multi-line area that displays plain text. "
You can set the font used by this component: but the point is that it uses a single font.
Perhaps you are looking for a JEditorPane (including JTextPane). Check out Sun's tutorial for code examples etc: http://java.sun.com/docs/books/tutorial/uiswing/components/text.html

Similar Messages

  • How to set Font to the ToolTip in JComboBox

    Hi,
    I am having problem in setting font to the ToolTip for JComboBox.
    Help needed asap...
    TIA,
    CK

    From the Mail menu bar click Mail > Preferences then select the Fonts & Colors tab.
    You can reset fonts sizes from there.
    Another way to open Mail Preferences, with Mail running, press Command ,  (comma) on your keyboard.
    The Mavericks upgrade may have reset that data to factory settings.

  • My Bose SIE2i volume control does not work. (pause/play does work). This is the secone set - the apple store in Sydney replaced the firsat set that had the same problem. It was working OK and has stopped.

    My Bose SIE2i volume control does not work. (pause/play does work). This is the second set - the apple store in Sydney replaced the first set that had the same problem. It was working OK and has stopped.

    Thanks again V.K. I did check the layout, and it was listed as alphabet when I inputted the password. So that doesn't seems to the the issue.
    Just finished a truly mystifying experiment, but I put in a shorter password in the way mentioned earlier and it worked. I then systematically kept increasing the characters of that password and it seems that if the password starts to exceed about 16, it stops recognizing it. I am fairly sure it is not the password itself since it never gives an error when typing in the verification password. So unless I systematically make the exact mistake twice at the setup screen, and then don't or make a different mistake every time at the login screen, I don't think its my typing skill.
    So problem solved for now, but I am still a bit worried. Maybe I should completely reinstall and use a shorter password.
    Is there supposed to be a length limit?

  • Setting font on the oracle.xml.dbviewer.DBViewer Bean

    Hi there,
    I'm working with the DBViewer class in oracle.xml.dbviewer. I'm feeding it an XML
    doc and XSL to produce output for a query. Everything works fine, however some
    of my data is in Unicode (UTF-8) format. I'm unable to set the font in the DBViewer
    in order to display the unicode characters. I've tried myDbViewer.setFont(myUniFont)
    but that doesn't work.
    Do I need to do something to the XSL in order to handle unicode?
    Thanks much in advance!
    -Toby

    Hi there,
    I'm working with the DBViewer class in oracle.xml.dbviewer. I'm feeding it an XML
    doc and XSL to produce output for a query. Everything works fine, however some
    of my data is in Unicode (UTF-8) format. I'm unable to set the font in the DBViewer
    in order to display the unicode characters. I've tried myDbViewer.setFont(myUniFont)
    but that doesn't work.
    Do I need to do something to the XSL in order to handle unicode?
    Thanks much in advance!
    -Toby

  • Setting font on the label of JTabbedPane tabs

    I want to change the font of a tab in a JTabbedPane if the tab is selected. Is there a way of doing this? I have tried
              Font f = new Font("Times New Roman", Font.BOLD, 12);
              UIManager.put("JTabbedPane.selectHighlight", f);
    and doesn't seem to help.
    thanks.

    I would suspect that selectHighlight is not a color property, not a font property. It might not have separate fonts for selected tabs. JTabbedPane is seriously lacking in several ways. There are other, better tabbed pane implementations out there.
    Generally, though, you'd probably have to create your own tabbed pane UI class to get the effect you want.

  • Understanding this message panel with the set font

    heyall, can someone explain to me how this messagepanel class works with setNewFont class, I cannot understand the correlation in the below lines?? i.e. there is no getFont class in the messagepanel so why use it?what does it do?
    //Set font for the message
            Font font = messagePanel.getFont();
            messagePanel.setFont(new Font(font.getName(),fontStyle, font.getSize()));
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class CheckBoxDemo  extends ButtonDemo{
        //Create three check boxes to control the display of message
        private JCheckBox jchkCentered = new JCheckBox("Centered");
        private JCheckBox jchkBold = new JCheckBox("Bold");
        private JCheckBox jchkItalic = new JCheckBox("Italic");
        public static void main(String[]args){
            CheckBoxDemo frame = new CheckBoxDemo();
            frame.setTitle("CheckBoxDemo");
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(500,200);
            frame.setVisible(true);
        public CheckBoxDemo() {
            //Set mnemonic keys
            jchkCentered.setMnemonic('C');
            jchkBold.setMnemonic('B');
            jchkItalic.setMnemonic('I');
            //Create a new panel to hold check boxes
            JPanel jpCheckBoxes = new JPanel();
            jpCheckBoxes.setLayout(new GridLayout(3,1));
            jpCheckBoxes.add(jchkCentered);
            jpCheckBoxes.add(jchkBold);
            jpCheckBoxes.add(jchkItalic);
            add(jpCheckBoxes,BorderLayout.EAST);
            //Registar listeners with checkboxes
            jchkCentered.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    messagePanel.setCentered(jchkCentered.isSelected());
                    jchkCentered.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    setNewFont();
                    jchkCentered.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    setNewFont();
        private void setNewFont() {
            int fontStyle = Font.PLAIN;
            fontStyle += (jchkBold.isSelected() ? Font.BOLD : Font.PLAIN);
            fontStyle += (jchkItalic.isSelected() ? Font.BOLD : Font.PLAIN);
            //Set font for the message
            Font font = messagePanel.getFont();
            messagePanel.setFont(new Font(font.getName(),fontStyle, font.getSize()));
    import java.awt.FontMetrics;
      import java.awt.Dimension;
      import java.awt.Graphics;
      import javax.swing.JPanel;
      public class MessagePanel extends JPanel{
        /** The message to be displayed */
        private String message = "Welcome to Java";
        /** The x coordinate where the message is displayed */
        private int xCoordinate = 20;
        /** The y coordinate where the message is displayed */
        private int yCoordinate = 20;
        /** Indicate whether the message is displayed in the center */
        private boolean centered;
        /** The interval for moving the message horizontally and vertically */
        private int interval = 10;
        /** Construct with default properties */
      //  public MessagePanel() {
        /** Construct a message panel with a specified message */
        public MessagePanel(String message) {
          this.message = message;
        /** Return message */
        public String getMessage() {
          return message;
        /** Set a new message */
        public void setMessage(String message) {
          this.message = message;
          repaint();
        /** Return xCoordinator */
        public int getXCoordinate() {
          return xCoordinate;
        /** Set a new xCoordinator */
        public void setXCoordinate(int x) {
          this.xCoordinate = x;
          repaint();
        /** Return yCoordinator */
        public int getYCoordinate() {
          return yCoordinate;
        /** Set a new yCoordinator */
        public void setYCoordinate(int y) {
          this.yCoordinate = y;
          repaint();
       /** Return centered */
        public boolean isCentered() {
          return centered;
        /** Set a new centered */
        public void setCentered(boolean centered) {
          this.centered = centered;
          repaint();
        /** Return interval */
        public int getInterval() {
          return interval;
        /** Set a new interval */
        public void setInterval(int interval) {
          this.interval = interval;
          repaint();
        /** Paint the message */
        protected void paintComponent(Graphics g) {
          super.paintComponent(g);
          if (centered) {
            // Get font metrics for the current font
            FontMetrics fm = g.getFontMetrics();
            // Find the center location to display
            int stringWidth = fm.stringWidth(message);
            int stringAscent = fm.getAscent();
            // Get the position of the leftmost character in the baseline
            xCoordinate = getWidth() / 2 - stringWidth / 2;
            yCoordinate = getHeight() / 2 + stringAscent / 2;
          g.drawString(message, xCoordinate, yCoordinate);
        /** Move the message left */
        public void moveLeft() {
          xCoordinate -= interval;
          repaint();
        /** Move the message right */
        public void moveRight() {
          xCoordinate += interval;
          repaint();
        /** Move the message up */
        public void moveUp() {
          yCoordinate -= interval;
          repaint();
        /** Move the message down */
        public void moveDown() {
         yCoordinate += interval;
          repaint();
        /** Override get method for preferredSize */
        public Dimension getPreferredSize() {
          return new Dimension(200, 30);
      }

    ah right so because there is an import fontmetrics api attached to that is a getFont method......i see now

  • 2 diffrent Fonts in a JTextArea?

    Hello... it is probably an easy question.
    Is it possible to set the Font of the JTextArea for two diffrent lines?
    here is my code:
    import java.awt.Color;
    import java.awt.Font;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextArea;
    public class MainFrame extends JFrame{
          * @param args
         public MainFrame(){
              JFrame frame = new JFrame("asd");
              JPanel myPanel = new JPanel();
              Font fBolt = new Font("font1",Font.BOLD, 12);     
              Font fPlein = new Font("font2",Font.PLAIN, 12);     
              JTextArea myArea = new JTextArea();
              myArea.setFont(fBolt);
              myArea.append("NAME\n");
              myArea.setFont(fPlein);
              myArea.append("SURNAME");
              myPanel.add(myArea);
              frame.add(myPanel);
              frame.setSize(200, 200);
              frame.setVisible(true);
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              MainFrame ma = new MainFrame();
    }What I wanted to se was NAME in Bold and SURNAME in normal text.
    Is it possibile?
    Thanks in advance. Any hints could be useful
    Mandy

    Is it possible to set the Font of the JTextArea for two diffrent lines?Unfortunately it is not possible :(
    I was joking ;-) It is possible, but not in JTextArea, you have to use JTextPane or JEditorPane for this purpose. Specially, JTextPane is ideal.
    To know how to use these components, have a look at these tutorial trails:
    [http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html]
    [http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html]
    [http://java.sun.com/docs/books/tutorial/uiswing/components/text.html]
    Thanks!
    Edit: A sample using JEditorPane:
    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class MainFrame2 extends JFrame {
        public MainFrame2() {
            JFrame frame = new JFrame("asd");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JPanel myPanel = new JPanel();
            JEditorPane myArea = new JEditorPane();
            myArea.setContentType("text/html");
            myArea.setText("<html><body>NAME:<br/><b>SURNAME:</b></body></html>");
            myPanel.add(myArea);
            frame.getContentPane().add(myPanel);
            frame.setSize(200, 200);
            frame.setVisible(true);
        public static void main(String[] args) {
            MainFrame2 ma = new MainFrame2();
    }Edited by: T.B.M on Feb 13, 2009 7:40 PM

  • How can I limit the fonts in the Character Map (charmap) and reinitialize the state after use?

    In a WPF application I have a RichTextBox in which users will be inserting text. I also must give the user the ability to insert characters. To do so I have called up charmap.exe using
    Process charProcess = new Process();
    ProcessStartInfo startInfo = new ProcessStartInfo();
    charProcess.StartInfo.FileName = strCharmap;
    charProcess.Start();
    etc., and it works fine. There are several problems I have basically with charmap, however, not with WPF. The first is that because of the subsequent use of the user’s insertion in the RTB, I must restrict the font to “Ariel Unicode
    MS.”  So far all I have been able to do is instruct and warn the user not to change fonts and 
    change back any font change that occurs as a result of use of “Advanced view” features.
    Question number one is, how can I restrict the fonts loaded into charmap to this one font? The second problem is that if another font is called up, or the “Advanced view” state of charmap is closed, or a “Group by” feature is opened, these choices will
    be retained for the next user that opens charmap. How can I initialize the state of charmap for each new user with the correct font and “Advanced view” features showing. It is said,but in old posts, that reinitialization occurs for all but administrative users,
    but this seems to be no longer true. I have tried permission changes in charmap’s Properties, but I can’t get the necessary reinitialization to occur even if user’s don’t have modify permission. Can one use a .ini file, or the .mui file, or make Registry changes
    to accomplish my goals. There seems to be a warning in the .mui file about changing fonts, but is it cancelled? I am using Windows 7 and C#.
    I have looked at other character maps but they are either too complicated for the casual user, or they have no search engine and advanced features, or they have the same problems.
    I am pretty much a novice with respect to the Windows files use and WPF, so please be fairly clear, complete, and prescriptive in your answer. Also so that I and others can learn, it would be nice to have an explanation of why one does whatever you suggest.
    Your help is appreciated.

    Hi,
    Thanks for your post!
    According to your description, I am afraid your problem is out of support in C#language forum. So i move your thread to off-topic forum!
    Best Wishes!
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and
    makes it easier for other visitors to find the resolution later.

  • How to save font information in jtextarea????????????

    I am trying to develop a notepad. I have successed in changing the font in the jtextarea. But we i close the file and open it again. It show only the plain text and lose all the changes about the font. How can i handle this ?

    Check if you create the text area or another object which deals with the font newly.

  • Problem with the JTextArea

    I'm using the swing packege 1.1 and having some problem when trying to limit the number of character per line in a JTextArea component.
    I want the JTextArea to change line when a certain number of character are typed in one of these lines.
    Any idea?
    thank you all.

    Do you mean you want to set the number of characters per line for example to 20 so all the lines in the JTextArea will hold only 20 characters? If so, this code shows a way to do it. If you use a fixed-width font, as in the example, all lines will hold the same number of characters. If you use a variable-width font, you could have lines with slightly more or slightly fewer characters, depending on what the user enters. The frame must not be resized.
          int chars_per_line=20;
          JFrame jf=new JFrame();
          JTextArea jta=new JTextArea(24,chars_per_line);
          jta.setFont(new Font("Courier",Font.PLAIN,14));
          jta.setLineWrap(true);
          jf.getContentPane().add(jta);
          jf.pack();
          jf.setResizable(false);
          jf.setVisible(true);

  • Set fonts of chapter title so the reader will not be able to change it

    Would it be possible to set the fonts of my Chapter title so the reader will not be able to change it like the fonts elsewhere in my book? i.e. If the reader changes the fonts, only the fonts in the paragraphs will change but not the chapter title.
    Thank you.

    On the USA Apple site it states that the iphone5c is available unlocked as stated below.
    If you buy iPhone for T-Mobile, it will arrive with a nano-SIM card already installed that you can activate by visiting an Apple Retail Store or a T-Mobile store or by calling T-Mobile. If you buy a SIM-free iPhone, you will need to purchase a GSM-compatible nano-SIM card separately. In the United States, you can purchase such a SIM from AT&T or T-Mobile. When you travel internationally, you can use a nano-SIM card for iPhone 5c from a local GSM carrier. The unlocked iPhone 5c model is A1532 (GSM). For details on LTE support, see www.apple.com/iphone/LTE.
    The ipad is the same in USA as in most other countries.
    However, the warranties are specific to the country the iphones and ipads are sold in, so if you need to have one replaced under warranty, you could have a problem. Personally, I don't quite 'get it.' We are in a very big city and at one Apple store that is always very crowded there is constantly a crowd of international tourists who buy many Apple products. We've seen one tourist buying eight to ten ipads! I wonder when I see them if they're aware of the warranty issue or if they have a way to work around it or if they're going to chance it.
    So I suggest you research this a little more before you decide. It's too bad that the prices vary so greatly from country to country. It could be customs and other taxes, but it would be great if this could somehow be changed.
    Hope this helps.

  • How to set font in JTextArea

    There is a function setFont() in class JTextArea, but it seems i only can set "bold","Italic" and "font size", but i want to set something like "Times new roman" and "Courier New"
    who knows how to set?
    //

    If your Java Runtime isn't configured (for whatever reason) to see the fonts you want, setting the font's name might just set it to the default value. Hence it looks like nothing happened.
    To see what fonts are available:String[] fontNames = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    for (int j=0; j<fontNames.length; j++)
      System.out.println(fontNames[j]);To set a font:String fontname = "Courier New";
    int style = Font.PLAIN;
    int size = 12;
    Font f = new Font(fontname, style, size);
    jtextfield.setFont(f);
    NOTE: I haven't tested the above code. But it's the right idea.

  • I am very annoyed at the Creative Cloud set up and the non-stop issues and problems

    I am very annoyed at the Creative Cloud set up and the non-stop issues and problems!  I am paying monthly for this service and it is constantly failing in some way!  So far in three months I have had to uninstall and re-install Photoshop THREE times because it stopped working properly and Illustrator I have had to do that same to TWICE!  That isn't including the other apps that have had issues!  I don't have the time to constantly be un-installing and re-installing all or some of the Creative Cloud because your developers are not making a product that works consistently for the money you are charging!  It is costing me more than just this monthly fee!  And I am even less impressed with the fact that I cannot email someone for assistance in resolving these issues.  Really Adobe?

    Adobe contact information - http://helpx.adobe.com/contact.html may help

  • I have a IPhone 5 and Iphone 5s. Both are set up with the same account ID and running IOS 8.0.2. When the phones are connected to the same Wifi at home, both phones will ring when someone call in to one of the phone.  Anyway to solve this problem?

    I have a IPhone 5 and Iphone 5s, each phone is activited with a different service provider. Both are set up with the same account ID and running IOS 8.0.2. When the phones are connected to the same Wifi at home, both phones will ring when someone call in to one of the phone.  Hence you do not know exactly which line the caller called.  If you answered using the wrong phone, then anyone calling the other number will not get through.  Anyway to solve this problem?

    Hey David Koh TP,
    Thanks for the question. It sounds like your devices are set up to use continuity together. Specifically, it sounds like you are signed into the same Apple ID in FaceTime, and have iPhone Cellular Calls enabled. To resolve your issue, simply disable this setting:
    Connect your iPhone, iPad, and iPod touch using Continuity
    http://support.apple.com/kb/HT6337
    Turn off iPhone cellular calls
    To turn off iPhone Cellular Calls on a device, go to Settings > FaceTime and turn off iPhone Cellular Calls.
    Thanks,
    Matt M.

  • I can't send emails from Mail. I have three different accounts set up and have the same problem with all. The mail just sits in my outbox. All worked fine until Yosemite upgrade. Recent update has not fixed problem.

    I can't send emails from Mail. I have three different accounts set up and have the same problem with all. The mail just sits in my outbox. All worked fine until Yosemite upgrade. Recent update has not fixed problem.

    I have been experiencing the same problem. My mail app won't even open on my Late 2011 Macbook Pro. It will show as open, but the app will never actually show up.

Maybe you are looking for

  • Window 8 upgrade has really messed up my PC.

    As a result of a Window 8 upgrade on 5th Dec and caused major problems for my PC I now have the following Failure ID on my PC. Failure ID: UAG7MX-6JW7AN-MFPXOK-61D303, Product ID: C4M14EA#ABU, Hard Disk 1. Can anybody explain the problem and how to r

  • Cover flow view problem

    I'm having an issue with cover flow view of images in OS 10.6.8 Whenever a jpeg or tiff file is edited in Photoshop (image size not changed) the preview of that picture in cover flow view becomes smaller, pixelated and it never clears up. Cover flow

  • Is there a way to export link info (scale %, effective ppi, etc.) to a spreadsheet?

    We have several retail pieces that use the same images multiple times. We upsize the image to the largest scale that is used in multiple layouts and then use that same image in the smaller pieces. We'd like to be able to export the link info from sev

  • Exchange 2013 resubmit mails

    HI all, Experiencing issue With Exchange 2013 environment ( 2 servers With cas and mailbox role With DAG)where some of Our emails are beeing resubmitted. So far cant see any pattern on why or where it sends Message twice to a recepient. Any idea wher

  • FF was hanging up on shutdown after I cleared 'Recent History' until I turned off Hardware Acceleration??

    I cleared the recent history to get rid of some sign-in errors. FF hung up on shutdown. I forced a quit and restarted the computer (Mac OS 10.5). Same problem. Turned off Hardware Acceleration and the problem cleared???