[4498] in java-interest
Re: Help with Dialog boxes
daemon@ATHENA.MIT.EDU (Amy Fowler)
Wed Jan 3 13:51:40 1996
Date: Wed, 3 Jan 1996 09:03:46 -0800
From: aim@scndprsn.eng.sun.com (Amy Fowler)
To: java-interest@java.Eng.Sun.COM, knrc@impmh.uucp@sun.com
>>
>>In one of my noddy programs I wanted to create a Dialog which
>>would display an error message and an OK button, for no other
>>reason than to try using Dialogs.
>>
>>My constructor creates a Label and a button, tries to resize
>>them according to the font being used and then calls pack to
>>get the Dialog resized with the preferred size of each
>>component. When my dialog is shown the Dialog window is smaller
>>than is required to display both the label and button.
Humm. I tried out your code (in the little program included
below) and the dialog appeared correctly for me.
What version of Java are you using? Also, what platform are
you seeing this problem on?
Regards,
Amy Moore-Fowler
Java Products Group
Sun Microsystems, Inc.
---------------------------------------------------------------------------
import java.awt.*;
class MyDialog extends Dialog {
MyDialog(Frame parent, boolean modal, String errormsg)
{
this(parent, "Error Dialog", modal, errormsg) ;
}
MyDialog(Frame parent, String title, boolean modal, String errormsg)
{
super(parent, title, modal) ;
Label myLabel = new Label(errormsg, Label.CENTER) ;
Graphics gc = parent.getGraphics() ;
FontMetrics fm = gc.getFontMetrics() ;
myLabel.resize(fm.stringWidth(errormsg), fm.getHeight()) ;
add("North", myLabel) ;
Button mybutton = new Button("OK") ;
mybutton.resize(fm.stringWidth(mybutton.getLabel()), fm.getHeight()) ;
add("South", mybutton) ;
pack() ;
list() ;
}
public boolean action(Event evt, Object what)
{
if ("OK".equals(evt.arg))
{
list() ;
dispose() ;
return true ;
}
return false ;
}
public static void main(String args[]) {
Frame frame = new Frame();
frame.show();
MyDialog dialog = new MyDialog(frame, false, "A Simple Test Message");
dialog.show();
}
}
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com