Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 02-23-2006, 03:13 PM   #1 (permalink)
Upright
 
Location: upstate NY
[java] identifier expected

I am trying to change the default behavior of a JTextArea. I want to change the font, the font flags, and the font size of the text entered into the area. Here is my code in its amazing entirety:

Code:
JTextArea canvas = new JTextArea(30,70);
canvas.setFont(new Font("Arial", Font.BOLD | Font.ITALIC, 20));
I am getting a compiler error specifying "identifier expected" for the 2nd line. It is complaining about the call to setFont(), which is a method inherited from Component. I posted this on a programming-oriented forum on another site and everyone is baffled and says my code should be fine. I am using JDK5 and compiling using javac.

I am thinking that perhaps I have an error elsewhere (and above) in my code and that perhaps it is cascading down to this function call....

The weird thing is if I comment out the 2nd line and replace it with:

Locale l = canvas.getLocale();

it works fine. In other words, it handles other Component methods perfectly fine, which tells me it doesn't like my call to setFont. I checked the method's definition out in the java docs and according to Sun, the signature for setFont() is this:

public void setFont(Font f)

So I don't see what I am missing here...
__________________
"Forty-three species of parrot? Nipples for men?? SLUGS!! God created slugs?!? I mean, are we not in the hands of a complete lunatic? If I had had my way, we would have started with laser beams, 8 o'clock, Day 1." -Evil
zharvey is offline  
Old 02-23-2006, 03:59 PM   #2 (permalink)
Sky Piercer
 
CSflim's Avatar
 
Location: Ireland
It certainly seems about right to me....don't see anything wrong with it...

maybe you could post some more of the code preceeding it?
__________________
CSflim is offline  
Old 02-23-2006, 04:25 PM   #3 (permalink)
Junkie
 
Location: San Francisco
Maybe too obvious, but did you import java.awt.Font?

Change it to
Code:
java.awt.Font f = new java.awt.Font("Arial", java.awt.Font.BOLD | java.awt.Font.ITALIC, 20);
JTextArea canvas = new JTextArea(30,70);
canvas.setFont(f);
and see if it complains about the first line.
__________________
"Prohibition will work great injury to the cause of temperance. It is a species of intemperance within itself, for it goes beyond the bounds of reason in that it attempts to control a man's appetite by legislation, and makes a crime out of things that are not crimes. A Prohibition law strikes a blow at the very principles upon which our government was founded." --Abraham Lincoln

Last edited by n0nsensical; 02-23-2006 at 09:43 PM..
n0nsensical is offline  
Old 02-24-2006, 07:09 AM   #4 (permalink)
Upright
 
Location: upstate NY
Yeah I imported Font from the AWT. Actually a poster on another website suggested that its a cascading error from previous code. But that makes no sense because replacing it with a call to any other Component-inherited method works perfectly fine.

It either doesn't like setFont() or the argument I am passing it....which makes no sense again because I am using the correct signature....oy vey.
__________________
"Forty-three species of parrot? Nipples for men?? SLUGS!! God created slugs?!? I mean, are we not in the hands of a complete lunatic? If I had had my way, we would have started with laser beams, 8 o'clock, Day 1." -Evil
zharvey is offline  
Old 02-24-2006, 07:46 AM   #5 (permalink)
Lover - Protector - Teacher
 
Jinn's Avatar
 
Location: Seattle, WA
Use a canvas.setFont(null) .. what's it throw then? Same thing?
__________________
"I'm typing on a computer of science, which is being sent by science wires to a little science server where you can access it. I'm not typing on a computer of philosophy or religion or whatever other thing you think can be used to understand the universe because they're a poor substitute in the role of understanding the universe which exists independent from ourselves." - Willravel
Jinn is offline  
 

Tags
expected, identifier, java


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 05:54 AM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73