Results 21 to 25 of 25
Thread: Change font color
- 01-17-2013, 01:23 AM #21
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
- 01-17-2013, 11:42 AM #22
Member
- Join Date
- Nov 2012
- Location
- India
- Posts
- 70
- Rep Power
- 0
Re: Change font color
Hi,
you use this modified code... this is working for me.. so you will try this..
{
for(int i = 1; i<= 9; i++){
if(a.getSource() == button[i]){
button[i].setText("X");
button[i].setEnabled(true);
button[i].setFont(new Font("Sans Serif", Font.PLAIN, 75));
button[i].setForeground(Color.green);
}
}
}
else
{
for(int i = 1; i<= 9; i++){
if(a.getSource() == button[i]){
button[i].setText("O");
button[i].setEnabled(true);
button[i].setFont(new Font("Sans Serif", Font.PLAIN, 75));
button[i].setForeground(Color.red);
}
I think setForeground is works in the time of setEnabled(true) otherwise it is not work..
Thanks,
- 01-17-2013, 11:46 AM #23
Member
- Join Date
- Nov 2012
- Location
- India
- Posts
- 70
- Rep Power
- 0
Re: Change font color
Hi
You use this code i hope this will be help to u..
This is work for me...
if (turn == 1 || turn==3 || turn==5 || turn==7 || turn== 9)
{
for(int i = 1; i<= 9; i++){
if(a.getSource() == button[i]){
button[i].setText("X");
button[i].setEnabled(true);
button[i].setFont(new Font("Sans Serif", Font.PLAIN, 75));
button[i].setForeground(Color.green);
}
}
}
else
{
for(int i = 1; i<= 9; i++){
if(a.getSource() == button[i]){
button[i].setText("O");
button[i].setEnabled(true);
button[i].setFont(new Font("Sans Serif", Font.PLAIN, 75));
button[i].setForeground(Color.red);
}
thanks,
- 01-17-2013, 07:53 PM #24
Member
- Join Date
- Jan 2013
- Posts
- 13
- Rep Power
- 0
Re: Change font color
God bless you bthank you !!
- 01-17-2013, 10:58 PM #25
Member
- Join Date
- Jul 2012
- Posts
- 55
- Rep Power
- 0
Re: Change font color
With setting the button to enabled you will be able to click on it after it already has been chosed. This code worked for me and allowed me to change to whatever color you would like.
Java Code:for(int i = 1; i<= 9; i++){ if(a.getSource() == button[i]){ button[i].setText("<html><font color = yellow>X</font></html>"); button[i].setEnabled(false); button[i].setFont(new Font("Sans Serif", Font.PLAIN, 75));
Similar Threads
-
Dynamically change the font and color message to be displayed on a panel.
By jeskoston in forum New To JavaReplies: 5Last Post: 05-09-2011, 06:28 AM -
Set Font Color, Font Style & Font Family While Replacing Text
By sherazam in forum Java SoftwareReplies: 0Last Post: 08-18-2010, 10:31 AM -
font color
By newbie123 in forum New To JavaReplies: 2Last Post: 03-01-2010, 03:58 PM -
How to change font/ font color etc in a graphic object using JCombobox?
By JavaInLove in forum AWT / SwingReplies: 5Last Post: 04-25-2009, 08:00 PM -
How to use TextAttribute class to change color and font of a text
By Java Tip in forum java.awtReplies: 0Last Post: 06-25-2008, 10:33 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks