 |
 |
NSButton's and key modifiers - maybe the stupidist question ever
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Okay, there has to be a REALLy easy answer to this. I'm having porblems getting NSButton objects to have key modifiers right when my app starts up. I'd like to just go in through IB and click on the button, type the charCode in, and compile on my happy way. But for whatever reason, IB deletes any charCode I enter besides the code for a couple (backspace,escape, etc). So i thought I'd write out the code by hand. Thr problem is that I can't invoke the setKeyModifier method on NSButtons right when my app starts up. I essentially need the user to call some method (click a button or something) that will set the keymodifiers.
This what I want my code to look like:
Code:
import blah.blah.blah
public class test
{
NSButton cool;
cool.setKeyModifier("c");
...
My other idea was this:
Code:
import blah.blah.blah
public class test
{
NSButton cool;
setKeys();
public setKeys()
{
cool.setKeyModifier("c");
...
But nothing works.
Thanks in advance,
F-bacher
P.S. Also, does anyone know (and I'm sure everyone does know) how to make a window come to front when ur app loads? My main window is always hidding behind Fire or whatever and I have to go click on it to bring it to front.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
What language..Java? Ok...
NSButton.setKeyEquivalent("c");
NSButton.setKeyEquivalentModifierMask( int );
And..
NSWindow.makeKeyAnOrderFront(this);
Now, if it works, great. If not, then I'm sorry.
Good luck!
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Bah, sorry. I meant setKeyEquivalent(), not setKeyModifie(). But ur right IamBob, that's what works... but not right away. Aka, I can't put the setKeyEquivalent method calls in public class whatever, I have to put it into one of the methods. But I can't use these methods untill a user invokes them, and I want the methods to be invoked independent of user action.
I hope that makes sense.
F-bacher
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
Oh, I see. You're looking for a way to do this stuff right away..
Code:
public void awakeFromNib() {
// do your stuff here.
}
Should work. I'm sorry, I mis-read, I guess.
Hope that works.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Originally posted by IamBob:
Oh, I see. You're looking for a way to do this stuff right away..
Code:
public void awakeFromNib() {
// do your stuff here.
}
Should work. I'm sorry, I mis-read, I guess.
Hope that works.
REALLY, that's it? COOL! Do I need to link it in Interface Builder, or does it automatically know what to do with that method at compile time (aka to invoke it when the app is opened)?
Thank,
F-bacher
Can't wait try this at home and stop taking Poly Sci Tests...
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Nov 2000
Status:
Offline
|
|
*If* that's really how you're supposed to do it it should be called auto-magically.
But, if that doesn't work remove the handles to your buttons from your code....
like, in IB you have 2 buttons: (bob) and (joe)
you connect them to whichever Class you're using them from in IB and then, in your code put:
Code:
// assuming the outlet names are the same as the button names..
//NSButton bob;
//NSButton joe;
then run the thing. It'll complain that it can't connect the outlets and at the same time will tell you a couple methods to use to get a handle for "bob" and "joe".
something like:
Code:
NSButton bob1; //instead of bob.
....
public void setBob(NSButton bob) {
bob1 = bob;
//the rest of the stuff you want to do..
}
*scratches his head*
I hope you figure something out cause I'm starting to confuse myself here.
Anyway, one of those ideas is bound to work. I used the "missing outlet" trick in Nicer.
[This message has been edited by IamBob (edited 02-22-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Okay, I can get the window to come to front in that nib method u told me about, and I can even set the keyEquivs (I know it works because I displayed the key Equivs in a test text box)... but when I hit those keys, nothing happens. And the weird thing, is I got keyEquivs to work at one point... weird.
F-bacher
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|