Setting One Font for All Swing Components in a Panel

H

Hal Vaughan

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
 
S

SadRed

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);
}

...
}
 
H

Hal Vaughan

Andrew said:
...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
 
A

Andrew Thompson

...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.
 
H

Hal Vaughan

Andrew said:
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
 
B

Brandon McCombs

Hal said:
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.
 
P

Patricia Shanahan

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
 
H

Hal Vaughan

Patricia said:
Brandon McCombs wrote:
...

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
 
H

Hal Vaughan

Brandon said:
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
 
H

Hal Vaughan

SadRed said:
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
 
L

Lew

Hal said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top