🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
1 messages
1 total messages Started by Sven Goetgeluck Fri, 09 Jan 2004 17:17
JDialog - default button - keyevent
#1335
Author: 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 ) {}
    }

}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads