Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSButton's and key modifiers - maybe the stupidist question ever

NSButton's and key modifiers - maybe the stupidist question ever
Thread Tools
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Feb 21, 2001, 05:10 PM
 
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
Reply With Quote
Feb 21, 2001, 05:57 PM
 
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
Reply With Quote
Feb 21, 2001, 06:13 PM
 
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
Reply With Quote
Feb 22, 2001, 09:45 AM
 
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
Reply With Quote
Feb 22, 2001, 09:49 AM
 
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
Reply With Quote
Feb 22, 2001, 03:40 PM
 
*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
Reply With Quote
Feb 22, 2001, 08:07 PM
 
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
     
   
Thread Tools
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -5. The time now is 12:27 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2