🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #1335

JDialog - default button - keyevent

#1335
From: Sven Goetgeluck
Date: Fri, 09 Jan 2004 17:17
120 lines
4264 bytes
Hi ,

I have my own dialogs like warningdialogs where i put 2 buttons on it
ok button
cancel button

but i cannot figure out how to program the default selected button
so fe okbutton is default
when de dialog showup i can press ok
only by enter or by the "o" button is this easy to do??

import java.awt.*;
import javax.swing.*;
import java.util.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;
import com.borland.jbcl.control.*;
import components.dialogs.MyESCDialog;
import components.dialogs.MyDialogButton;


public class WarningDialog extends MyESCDialog {
  JPanel panel1 = new JPanel();
  MyDialogButton OKButton = new MyDialogButton();
  XYLayout xYLayout1 = new XYLayout();
  JLabel image = new JLabel();
  JLabel transparentImage1 = new JLabel();
  JLabel jLabel1 = new JLabel();
  JLabel filename = new JLabel();
  UtilityClass m_Utils = new UtilityClass();
  private ActionListener okListener = null;



  public WarningDialog(Frame frame, String title, boolean
modal,ResourceBundle r,ResourceBundle i) {
    super(frame, title, modal);
    this.setResourceBundle(r,i);
    try  {
      jbInit();
      pack();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }


  void jbInit() throws Exception {
    panel1.setLayout(xYLayout1);
    OKButton.setText(recources.getString("OK"));
    OKButton.addActionListener(okListener = new
java.awt.event.ActionListener() {

      public void actionPerformed(ActionEvent e) {
        OKButton_actionPerformed(e);
      }
    });
    xYLayout1.setHeight(116);
    xYLayout1.setWidth(365);
    transparentImage1.setIcon(new ImageIcon(images.getString("WARNING")));
    transparentImage1.setHorizontalAlignment(SwingConstants.CENTER);
    transparentImage1.setHorizontalTextPosition(SwingConstants.CENTER);
    panel1.setMaximumSize(new Dimension(370, 120));
    panel1.setMinimumSize(new Dimension(370, 120));
    panel1.setPreferredSize(new Dimension(370, 120));
    getContentPane().add(panel1);
    panel1.add(OKButton, new XYConstraints(139, 82, 92, 29));
    panel1.add(filename, new XYConstraints(87, 42, 267, 23));
    panel1.add(jLabel1, new XYConstraints(87, 13, 267, 26));
    panel1.add(transparentImage1, new XYConstraints(1, 5, 70, 70));
    this.setSize(370, 120);
    centerScreen();
  }

  void OKButton_actionPerformed(ActionEvent e) {
    dispose();
  }
  public void setReason(String r)
  {
   jLabel1.setText(r);
  }
  public void setFilename(String f)
  {
   filename.setText(f);
  }
       private void done()
    {
       OKButton.removeActionListener(okListener);
       m_Utils.removeAllComponents( this );
       dispose();
    }

//--------------------------------------------------------------------------
--
// finalize
//
// Added lots of stuff here!
// Always make sure you set ALL objects to null when working with Swing.
//--------------------------------------------------------------------------
--

  protected void finalize()
    {
     panel1 = null;
     OKButton = null;
     xYLayout1 = null;
     image = null;
     transparentImage1 = null;
     jLabel1 = null;
     recources = null;
     images = null;
     filename = null;
     m_Utils = null;
     okListener = null;

      try { super.finalize(); } catch( Throwable e ) {}
    }

}
Technical Details
Message-ID: <3ffee8b4$0$1810$ba620e4c@news.skynet.be>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!skynet.be!skynet.be!louie!tjb!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,88570505ac235f9f,start
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2004-01-09 09:45:38 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!skynet.be!skynet.be!louie!tjb!not-for-mail
From: "Sven Goetgeluck" <sven.goetgeluck@pandora.be>
Newsgroups: borland.public.jbuilder.java.swing
Subject: JDialog - default button - keyevent
Date: Fri, 9 Jan 2004 18:17:21 +0100
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Lines: 122
Message-ID: <3ffee8b4$0$1810$ba620e4c@news.skynet.be>
Organization: -= Belgacom Usenet Service =-
NNTP-Posting-Host: 194.78.186.55
X-Trace: 1073670325 reader0.news.skynet.be 1810 194.78.186.55:1831
X-Complaints-To: usenet-abuse@skynet.be