程序如下:我想把“更新按钮”这四个字调得大一些我用了b.setSize(200,100);可是不管我括号里得值设多少,它都没有变,到底是怎么回事啊??
public class OptionDialog extends JFrame implements ActionListener {
 
  JLabel label = null;  public OptionDialog() {
    super("更新程序");
   setSize(new Dimension(500, 300));
    Container contentPane = this.getContentPane();    JButton b = new JButton("更新按钮");
    b.setSize(200,100);//这一行代码怎么不起效果??
    b.setBackground(Color.LIGHT_GRAY);
    b.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,2));
    b.addActionListener(this);
    .......
    ......
}
...
}

解决方案 »

  1.   

    button的大小取决于你的Layout,setSize()此时已经被LayoutManager给忽略了。
    button上字的大小可以用设置Font的方式或者HTML Code来控制。
      

  2.   

    to remote_eyes() :
    你得意思是说下面这句话控制按钮得大小?setSize(new Dimension(500, 300));
    那我要想调下按钮得大小怎么办?必须把layout大小改了?这也太不方便了吧??
      

  3.   

    你要实现的只是按钮字体的改变,因此可以通过改变按钮的字体来调整它的大小和样式。还是用下面的例子来说明问题吧!
    package mypoj;
    import java.awt.*;
    import javax.swing.*;
    public class T1 extends JFrame
    {
        private JButton b;
        public T1() {
            super("更新程序");
            this.setLayout(new FlowLayout());
            b = new JButton("更新按钮");
    //以下两句将得到你想要得结果:
            Font f = new Font("宋体", 30, 30);
            b.setFont(f);
            this.add(b);
        }
        public static void main(String args[])          
        {
            T1 t=new T1();
            t.setSize(300,300);
            t.setVisible(true);
        }
    }
      

  4.   

    你方法不对
    setSize不是这个作用
    是setFont里的