Setting One Font for All Swing Components in a Panel

Discussion in 'Java' started by Hal Vaughan, Jun 5, 2007.

  1. Hal Vaughan

    Hal Vaughan Guest

    I've never had to worry about what font I was using before, but now I'm
    going to have a JComboBox with combined data from several sources and need
    to use a fixed width font so I can line up data. If possible, I'd like to
    just use the same font for all the components in that panel. I know I can
    set the font for each component individually and I did set the font for the
    panel, but that doesn't effect the components in the panel.

    Is there a way to specify a font for a panel or JTabbedPane and have that
    same font automatically used for all the components in the panel? Could
    this be done for a window? I'd like to just specify the font once and not
    over and over with each component.

    Thanks!

    Hal
    Hal Vaughan, Jun 5, 2007
    #1
    1. Advertising

  2. Hal Vaughan

    SadRed Guest

    On Jun 6, 1:09 am, Hal Vaughan <> wrote:
    > I've never had to worry about what font I was using before, but now I'm
    > going to have a JComboBox with combined data from several sources and need
    > to use a fixed width font so I can line up data. If possible, I'd like to
    > just use the same font for all the components in that panel. I know I can
    > set the font for each component individually and I did set the font for the
    > panel, but that doesn't effect the components in the panel.
    >
    > Is there a way to specify a font for a panel or JTabbedPane and have that
    > same font automatically used for all the components in the panel? Could
    > this be done for a window? I'd like to just specify the font once and not
    > over and over with each component.
    >
    > Thanks!
    >
    > Hal


    public class MyContainer extends JPanel{
    Font font;
    ...

    public void addImpl(Component comp, Object constraints, int index){
    comp.setFont(font);
    super.addImpl(comp, constraints, index);
    }

    ...
    }
    SadRed, Jun 5, 2007
    #2
    1. Advertising

  3. On Jun 6, 2:09 am, Hal Vaughan <> wrote:
    > I've never had to worry about ...


    ....multi-posting? Please refrain from
    multi-posting, in future.
    <http://www.physci.org/codes/javafaq.html#xpost>

    (X-post to c.l.j.p./g., w/ f/u to c.l.j.p. only))
    Andrew Thompson, Jun 5, 2007
    #3
  4. Hal Vaughan

    Hal Vaughan Guest

    Andrew Thompson wrote:

    > On Jun 6, 2:09 am, Hal Vaughan <> wrote:
    >> I've never had to worry about ...

    >
    > ...multi-posting? Please refrain from
    > multi-posting, in future.
    > <http://www.physci.org/codes/javafaq.html#xpost>
    >
    > (X-post to c.l.j.p./g., w/ f/u to c.l.j.p. only))


    Posted to one, needed the answer so I could move on to another item, so I
    posted it to another group. I didn't multi-post and had waited hours for
    an answer before posting to the 2nd group -- and then, only after realizing
    there was a better forum for that post (and that I needed an answer quickly
    if at all possible).

    The headers indicate that.

    Now, is there a chance you could help me out with this problem? I've
    essentially had to move on and drop this part of the GUI due to timing
    pressure, but if there's a quick and easy answer, it would be a huge help.

    Hal
    Hal Vaughan, Jun 6, 2007
    #4
  5. On Jun 6, 9:33 am, Hal Vaughan <> wrote:

    > ...had waited hours for
    > an answer before posting to the 2nd group ...


    You poor, poor thing. Perhaps if this matter is so
    urgent, you should hire a consultant, rather than
    treat these groups as if we (collectively) were your
    paid servants.

    For future reference, though I disagree with your
    impatience, a simple explanation at the second post
    would have sufficed. I might even have given you an
    answer.

    Andrew T.
    Andrew Thompson, Jun 6, 2007
    #5
  6. Hal Vaughan

    Hal Vaughan Guest

    Andrew Thompson wrote:

    > On Jun 6, 9:33 am, Hal Vaughan <> wrote:
    >
    >> ...had waited hours for
    >> an answer before posting to the 2nd group ...

    >
    > You poor, poor thing. Perhaps if this matter is so
    > urgent, you should hire a consultant, rather than
    > treat these groups as if we (collectively) were your
    > paid servants.
    >
    > For future reference, though I disagree with your
    > impatience, a simple explanation at the second post
    > would have sufficed. I might even have given you an
    > answer.
    >
    > Andrew T.


    Thank you, your worship.

    Hal
    Hal Vaughan, Jun 6, 2007
    #6
  7. Hal Vaughan wrote:
    > Andrew Thompson wrote:
    >
    >> On Jun 6, 9:33 am, Hal Vaughan <> wrote:
    >>
    >>> ...had waited hours for
    >>> an answer before posting to the 2nd group ...

    >> You poor, poor thing. Perhaps if this matter is so
    >> urgent, you should hire a consultant, rather than
    >> treat these groups as if we (collectively) were your
    >> paid servants.
    >>
    >> For future reference, though I disagree with your
    >> impatience, a simple explanation at the second post
    >> would have sufficed. I might even have given you an
    >> answer.
    >>
    >> Andrew T.

    >
    > Thank you, your worship.
    >
    > Hal


    Hal,

    You'll find it is better to simply ignore Andrew as he seems to annoy
    more than help by replying with useless messages concerning posting
    practices (you should have done this but not that and don't do this...).
    Hopefully at some point he will understand the error of his ways but I
    highly doubt it. Think of him as a self-proclaimed usenet moderator, one
    that can, thankfully, be ignored.
    Brandon McCombs, Jun 6, 2007
    #7
  8. Brandon McCombs wrote:
    ....
    > You'll find it is better to simply ignore Andrew as he seems to annoy
    > more than help by replying with useless messages concerning posting
    > practices (you should have done this but not that and don't do this...).
    > Hopefully at some point he will understand the error of his ways but I
    > highly doubt it. Think of him as a self-proclaimed usenet moderator, one
    > that can, thankfully, be ignored.


    Meanwhile, I hope that Hal did read SadRed's substantive response,
    suggesting overriding the JPanel's addImpl method with one that forces
    the font setting.

    Patricia
    Patricia Shanahan, Jun 6, 2007
    #8
  9. Hal Vaughan

    Hal Vaughan Guest

    Patricia Shanahan wrote:

    > Brandon McCombs wrote:
    > ...
    >> You'll find it is better to simply ignore Andrew as he seems to annoy
    >> more than help by replying with useless messages concerning posting
    >> practices (you should have done this but not that and don't do this...).
    >> Hopefully at some point he will understand the error of his ways but I
    >> highly doubt it. Think of him as a self-proclaimed usenet moderator, one
    >> that can, thankfully, be ignored.

    >
    > Meanwhile, I hope that Hal did read SadRed's substantive response,
    > suggesting overriding the JPanel's addImpl method with one that forces
    > the font setting.
    >
    > Patricia


    I've read it and have it noted. I had to switch over to a few other items
    for a while (I was hoping I could get an answer while I was still on the
    same section) and will be trying that when I get back to that topic. (And
    if I have some problems, of course, I'll be asking about those!)

    Thanks, both you and SadRed for a useful message!

    Hal
    Hal Vaughan, Jun 6, 2007
    #9
  10. Hal Vaughan

    Hal Vaughan Guest

    Brandon McCombs wrote:

    > Hal Vaughan wrote:
    >> Andrew Thompson wrote:
    >>
    >>> On Jun 6, 9:33 am, Hal Vaughan <> wrote:
    >>>
    >>>> ...had waited hours for
    >>>> an answer before posting to the 2nd group ...
    >>> You poor, poor thing. Perhaps if this matter is so
    >>> urgent, you should hire a consultant, rather than
    >>> treat these groups as if we (collectively) were your
    >>> paid servants.
    >>>
    >>> For future reference, though I disagree with your
    >>> impatience, a simple explanation at the second post
    >>> would have sufficed. I might even have given you an
    >>> answer.
    >>>
    >>> Andrew T.

    >>
    >> Thank you, your worship.
    >>
    >> Hal

    >
    > Hal,
    >
    > You'll find it is better to simply ignore Andrew as he seems to annoy
    > more than help by replying with useless messages concerning posting
    > practices (you should have done this but not that and don't do this...).
    > Hopefully at some point he will understand the error of his ways but I
    > highly doubt it. Think of him as a self-proclaimed usenet moderator, one
    > that can, thankfully, be ignored.


    Yes, I should have. It's been a rough week (already) during a very rough
    time and yes, I should have ignored him. I didn't post on both groups at
    the same time and there was a lot going on, but it must have been more
    important to him to make a judgement than to try to help.

    I was thinking of him very much as that self-proclaimed moderator, which was
    the reason for my remark.

    Thank you, as well as the others, who actually took the time to help me out
    or to tell me to blow it off.

    Hal
    Hal Vaughan, Jun 6, 2007
    #10
  11. Hal Vaughan

    Hal Vaughan Guest

    SadRed wrote:

    > On Jun 6, 1:09 am, Hal Vaughan <> wrote:
    >> I've never had to worry about what font I was using before, but now I'm
    >> going to have a JComboBox with combined data from several sources and
    >> need
    >> to use a fixed width font so I can line up data. If possible, I'd like
    >> to
    >> just use the same font for all the components in that panel. I know I
    >> can set the font for each component individually and I did set the font
    >> for the panel, but that doesn't effect the components in the panel.
    >>
    >> Is there a way to specify a font for a panel or JTabbedPane and have that
    >> same font automatically used for all the components in the panel? Could
    >> this be done for a window? I'd like to just specify the font once and
    >> not over and over with each component.
    >>
    >> Thanks!
    >>
    >> Hal

    >
    > public class MyContainer extends JPanel{
    > Font font;
    > ...
    >
    > public void addImpl(Component comp, Object constraints, int index){
    > comp.setFont(font);
    > super.addImpl(comp, constraints, index);
    > }
    >
    > ...
    > }


    Thanks. It took me a bit to go over this, but once I caught on, it makes
    sense. As I said in a separate reply to someone else, I'll be trying this
    when I get back to that particular section.

    I appreciate your time and effort!

    Hal
    Hal Vaughan, Jun 6, 2007
    #11
  12. Hal Vaughan

    Lew Guest

    Hal Vaughan wrote:
    > Brandon McCombs wrote:
    >> You'll find it is better to simply ignore Andrew as he seems to annoy
    >> more than help by replying with useless messages concerning posting
    >> practices (you should have done this but not that and don't do this...).
    >> Hopefully at some point he will understand the error of his ways but I
    >> highly doubt it. Think of him as a self-proclaimed usenet moderator, one
    >> that can, thankfully, be ignored.

    >
    > Yes, I should have. It's been a rough week (already) during a very rough
    > time and yes, I should have ignored him. I didn't post on both groups at
    > the same time and there was a lot going on, but it must have been more
    > important to him to make a judgement than to try to help.
    >
    > I was thinking of him very much as that self-proclaimed moderator, which was
    > the reason for my remark.
    >
    > Thank you, as well as the others, who actually took the time to help me out
    > or to tell me to blow it off.


    OTOH, of course, is that multi-posting is an annoying practice that makes it
    difficult to follow the conversations.

    It is arguable that Andrew should have been more diplomatic, but that doesn't
    necessarily invalidate his point.

    --
    Lew
    Lew, Jun 6, 2007
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mkrause
    Replies:
    0
    Views:
    663
    mkrause
    May 6, 2005
  2. Roedy Green

    AWT font != Swing Font

    Roedy Green, Aug 8, 2005, in forum: Java
    Replies:
    0
    Views:
    469
    Roedy Green
    Aug 8, 2005
  3. JC
    Replies:
    1
    Views:
    737
    Michael Rauscher
    Aug 9, 2006
  4. gonu
    Replies:
    2
    Views:
    275
    Ian Wilson
    Mar 13, 2007
  5. mttc
    Replies:
    2
    Views:
    2,371
    Roedy Green
    Jul 3, 2009
Loading...

Share This Page