当前位置: 技术问答>java相关
请问为什么dialog只看见标题栏
来源: 互联网 发布时间:2015-07-23
本文导语: 只能看见标题栏,但是可以用鼠标拉开边框。 我用了Jbuilder里面的XYLayout类,不只是不是这个影响,请问怎么解决? import java.awt.*; import java.awt.event.*; import javax.swing.*; import com.borland.jbcl.layout.*; public class OKDialog e...
只能看见标题栏,但是可以用鼠标拉开边框。
我用了Jbuilder里面的XYLayout类,不只是不是这个影响,请问怎么解决?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
public class OKDialog extends Dialog implements ActionListener
{
public static int Confirm;
private XYLayout xYLayout1 = new XYLayout();
private JButton okButton = new JButton("Ok");
private JButton canButton = new JButton("Cancel");
//private JLabel jLabel1 = new JLabel();
protected static Frame createdFrame;
public OKDialog(Frame parent, String message)
{
super(parent,true);
Label messageLabel = new Label(message);
//XYLayout xYLayout1 = new XYLayout();
setLayout(xYLayout1);
add(messageLabel,new XYConstraints(20, 26, 224, 21));
canButton.addActionListener(this);
add(canButton, new XYConstraints(121, 69, 82, 20));
okButton.addActionListener(this);
add(okButton, new XYConstraints(33, 69, 70, 20));
}
public void actionPerformed(ActionEvent event)
{
Object buttTmp=event.getSource();
if (buttTmp == okButton)
{
hide();
if (createdFrame != null)
{
createdFrame.hide();
}
Confirm=1;
}
if (buttTmp == canButton)
{
hide();
if (createdFrame != null)
{
createdFrame.hide();
}
Confirm=0;
}
}
public static void createOKDialog(String dialogString)
{
if (createdFrame == null)
{
createdFrame = new Frame("Dialog");
}
OKDialog okDialog = new OKDialog(createdFrame, dialogString);
createdFrame.setSize(okDialog.getSize().width,okDialog.getSize().height);
//createdFrame.setSize(270,300);
okDialog.show();
}
}
我用了Jbuilder里面的XYLayout类,不只是不是这个影响,请问怎么解决?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
public class OKDialog extends Dialog implements ActionListener
{
public static int Confirm;
private XYLayout xYLayout1 = new XYLayout();
private JButton okButton = new JButton("Ok");
private JButton canButton = new JButton("Cancel");
//private JLabel jLabel1 = new JLabel();
protected static Frame createdFrame;
public OKDialog(Frame parent, String message)
{
super(parent,true);
Label messageLabel = new Label(message);
//XYLayout xYLayout1 = new XYLayout();
setLayout(xYLayout1);
add(messageLabel,new XYConstraints(20, 26, 224, 21));
canButton.addActionListener(this);
add(canButton, new XYConstraints(121, 69, 82, 20));
okButton.addActionListener(this);
add(okButton, new XYConstraints(33, 69, 70, 20));
}
public void actionPerformed(ActionEvent event)
{
Object buttTmp=event.getSource();
if (buttTmp == okButton)
{
hide();
if (createdFrame != null)
{
createdFrame.hide();
}
Confirm=1;
}
if (buttTmp == canButton)
{
hide();
if (createdFrame != null)
{
createdFrame.hide();
}
Confirm=0;
}
}
public static void createOKDialog(String dialogString)
{
if (createdFrame == null)
{
createdFrame = new Frame("Dialog");
}
OKDialog okDialog = new OKDialog(createdFrame, dialogString);
createdFrame.setSize(okDialog.getSize().width,okDialog.getSize().height);
//createdFrame.setSize(270,300);
okDialog.show();
}
}
|
不是
应该加一句
okDialog.setSize(200,100);
应该加一句
okDialog.setSize(200,100);
|
其实在构造函数中加入
setSize(300,400)应该可以了
,xyLayout只是决定了对话框中的控件的放置方式
setSize(300,400)应该可以了
,xyLayout只是决定了对话框中的控件的放置方式
|
okDialog.setbounds(100,100,400,400)
主要是由于你没有设定dialog大小
主要是由于你没有设定dialog大小