Results 1 to 4 of 4
  1. #1
    Unsub's Avatar
    Unsub is offline Member
    Join Date
    Jan 2010
    Posts
    30
    Rep Power
    0

    Exclamation Font.PLAIN - Isn't setting Font back to a Plain Style - Need Help!

    Here's a small snipit of the code i've created;

    My problem:
    -When bold and italic are both false, the font refuses to reset to plain and remains bold.
    Java Code:
      public void setStyle(Boolean bold, Boolean italic){
            if(bold == true && italic == false)
                lblMain.setFont(new Font(lblMain.getFont().getFontName(), Font.BOLD, lblMain.getFont().getSize()));
            else if(bold == false && italic == true){
              lblMain.setFont(new Font(lblMain.getFont().getFontName(), Font.ITALIC, lblMain.getFont().getSize()));
            }
            else if(bold ==true && italic == true){
                lblMain.setFont(new Font(lblMain.getFont().getFontName(), Font.BOLD+Font.ITALIC, lblMain.getFont().getSize()));
            }
            else if(bold == false && italic == false){
               lblMain.setFont(new Font(lblMain.getFont().getFontName(), Font.PLAIN, lblMain.getFont().getSize()));
            }
        }
    here is the code that calls the above method:
    (the below code is present in the actionPerformed method of a JFrame that implements ActionListener)
    Java Code:
    else if(event.getSource() == chkBold || event.getSource() == chkItalic){
                setStyle(chkBold.isSelected(), chkItalic.isSelected());
            }
    Last edited by Unsub; 03-11-2010 at 11:13 AM. Reason: added more code

  2. #2
    Unsub's Avatar
    Unsub is offline Member
    Join Date
    Jan 2010
    Posts
    30
    Rep Power
    0

    Default

    Please note:
    a) I have verified that all components have been registered in the actionPerformed method via the componetName.addActionListener(this);
    b) The Italic feature works perfectly fine. When the chkItalic JCheckBox is selected, the lblMain JLabel is changed to Italic and resets when the chkItalic JCheckBox is unselected.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,005
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Unsub View Post
    Please note:
    a) I have verified that all components have been registered in the actionPerformed method via the componetName.addActionListener(this);
    b) The Italic feature works perfectly fine. When the chkItalic JCheckBox is selected, the lblMain JLabel is changed to Italic and resets when the chkItalic JCheckBox is unselected.
    What happens when you use getFamily() instead of getFontName()?

    kind regards,

    Jos

  4. #4
    Unsub's Avatar
    Unsub is offline Member
    Join Date
    Jan 2010
    Posts
    30
    Rep Power
    0

    Default

    works perfectly!

    thanks so much.

    I looked at the docs, but must have passed by the getFamily description....

    <slaps forhead>

Similar Threads

  1. font color
    By newbie123 in forum New To Java
    Replies: 2
    Last Post: 03-01-2010, 03:58 PM
  2. Replies: 5
    Last Post: 04-25-2009, 08:00 PM
  3. Indentation - plain text
    By barney75 in forum New To Java
    Replies: 1
    Last Post: 03-23-2009, 05:54 PM
  4. Font question
    By orchid in forum Java 2D
    Replies: 1
    Last Post: 08-01-2007, 02:03 AM
  5. convert html to plain text
    By vissu007 in forum New To Java
    Replies: 3
    Last Post: 07-07-2007, 02:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •