Q:  Why won't my textField become firstResponder?  The following code is in my appDidInit: method:

[[NXApp mainWindow] makeKeyAndOrderFront:self];
[[NXApp mainWindow] makeFirstResponder:myTextField];

The I-beam cursor does not appear in myTextField.  In the debugger, makeFirstResponder: returns the id of the window as it should.  And when asked, the window claims that the textField is the firstResponder. What's going on?

A: The problem is that makeFirstResponder: just sets the firstResponder.  It does not modify the selection. You have to explicitly set the selection if you want the cursor to appear in the TextField.  The method selectText: does the trick--and it calls makeFirstResponder: for you.  Try using the following code instead:

[[NXApp mainWindow] makeKeyAndOrderFront:self];
[myTextField selectText:nil];

The same is true of Form objects as well. For Forms you must do the following:

[[NXApp mainWindow] makeKeyAndOrderFront:self];
[myForm selectTextAt:0];



QA823

Valid for 1.0, 2.0, 3.0

Q:  I am trying to set the background color for my TextField.  It seems that the color is being ignored. What is going on?  Here is my code, which uses a color well:

- setBackgroundColorWithWell:sender
{
[myTextField setBackgroundColor:[sender color]];
[myTextField display];
return self;
}

A:  You must set shades in both the color model and the gray model separately.  The AppKit figures out what type of machine is being used and sets the window depth for the window accordingly.

The model of being able to specify colors and gray separately can be useful; typically you don't want to give a TextField some random color when it is displayed in a monochrome window.  For instance, yellow 12 point text on a red background is usually reduced a few pixels when displayed in a 2-bit window.  Thus, in most cases you might want a TextField to remain black on white on the monochrome display.  Or you might want to just alter the foreground while always keeping the background white.  If you do want the gray and color values to track, then you have to set them both, as shown below.

- setBackgroundColorWithWell:sender
{
[myTextField setBackgroundColor:[sender color]];
[myTextField setBackgroundGray: NXGrayComponent([sender color])];
[myTextField display];
return self;
}



QA756

Valid for 2.0, 3.0