Article View: borland.public.jbuilder.java.swing
Article #68Re: Button related question
From: Alexey N. Solofnenko
Date: Fri, 16 Dec 2005 04:16
Date: Fri, 16 Dec 2005 04:16
88 lines
3703 bytes
3703 bytes
I think you are looking for this:
dialog.getRootPane().setDefaultButton(submitButton);
- Alexey.
GEORGE wrote:
> Paul,
>
> Thanks for replying. I'm sorry to have made you type so much but my problem
> is much simpler than what you thought.
>
> I have a dialog with bunch of controls one of which is the OK button. What
> I want is that should the user press Enter when this dialog has been
> activated, then the actionPerformed of the OK button should be executed
> (even if the cursor is currently in , say, a text field). Hope this makes
> sense.
>
> George
>
> "Paul Nichols [TeamB]" <paul@comp.net> wrote in message
> news:43a22b75@newsgroups.borland.com...
>> GEORGE wrote:
>>
>>> I would like that when the user presses the Enter key in a dialog, the
>>> actionPerformed() of a designated button should be executed. Is there a
>>> button property for this purpose? How to achieve this effect?
>>>
>>> Thanks
>>>
>>> George
>> I am not exactly sure what you are asking, but I will take a stab at
>> making
>> an assumption.
>>
>>
>> You have a Dialog and you want to activate the Event listener on another
>> JFrame or JPanel. The solution is to get the instance of that parent
>> container.
>>
>> The easiest way to do this, is to have a static instance of the container
>> you wish to access. Example:
>>
>> public class MyJPanel extends JPanel {
>>
>> static MyJPanel panel;
>>
>>
>> public MyJPanel() {
>> super();
>>
>> }
>>
>> public static MyJPanel getMyJPanel(){
>> if(panel==null){
>> panel= new MyJPanel();
>> }
>> return panel;
>> }
>>
>>
>>
>> //Now call the getMyJPanel from the Dialog
>>
>> public void jDialogButton1_actionPerformed(ActionEvent actionEvent) {
>> MyJPanel panel=MyJPanel.getMyJPanel();
>> panel.jButton2_actionPerformed(null);
>> }
>>
>> Of course another and a much better way to do thisand avoid dependencies
>> upon your view Components, is to create Listener class(es) that will
>> implement listeners according to usage in the application. Those listeners
>> that would be commonly used in the application or which need to be able to
>> access methods across Frames, Dialogs, etc. could have static references
>> or
>> be contained in a static class. This enforces better separation between
>> classes. Since I do not know your programming background, I do not know
>> what to reference as a a concept here. If you have database programming
>> background, think of a linking table concept.
>>
>>
>>
>>
>
>
--
Alexey N. Solofnenko
home: http://trelony.cjb.net/
Technical Details
Message-ID:
<43a23efa$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<43a208cd@newsgroups.borland.com> <43a22b75@newsgroups.borland.com> <43a22e54$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,84ac8c3cf3b463d X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 15 Dec 2005 20:16:12 -0800 From: "Alexey N. Solofnenko" <nospam@nospam.comp> User-Agent: Thunderbird 1.5 (X11/20051214) MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing Subject: Re: Button related question References: <43a208cd@newsgroups.borland.com> <43a22b75@newsgroups.borland.com> <43a22e54$1@newsgroups.borland.com> In-Reply-To: <43a22e54$1@newsgroups.borland.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 67.180.237.5 Message-ID: <43a23efa$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1134706426 67.180.237.5 (15 Dec 2005 20:13:46 -0700) Lines: 88 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail