本帖最后由 qq565235633 于 2011-04-14 17:40:13 编辑

解决方案 »

  1.   

    好久没用swing了,忘光了。
    请XDJM们,速度告诉我一下。
    谢谢了
      

  2.   

    你代码写的太乱,你把他放到JPanel中,然后再设位置!
      

  3.   


    public static void main(String [] args){
    JFrame frame = new JFrame();

        frame.setTitle("加密");
        frame.setBounds(300, 300, 600, 400);
    //     JLabel encryptType = new JLabel("加密類型");
    //     encryptType.setSize(50, 100);
        JRadioButton encrypt_AES128 = new JRadioButton();
        encrypt_AES128.setText("加密類型");
            encrypt_AES128.setSize(50,200);
    //        frame.add(encryptType);
            frame.add(encrypt_AES128);
            frame.setVisible(true);
            frame.setResizable(false);
    }
      

  4.   

    楼主兄弟,你这个swing写的有问题,你没有获取frame的内容面板(即Container)就直接添加内容进去,那当然只会显示最后一个组件,也就是你上面的单选按钮,所以要正常显示的话就先获取frame的内容面板再添加内容,如下:
        JFrame frame = new JFrame();
        frame.setTitle("加密");
        frame.setBounds(300, 300, 600, 400);     Container con = frame.getContentPane();//获取frame的内容面板
        con.setLayout(new FlowLayout());//把内容面板设置为流式布局(其他的布局也行)     JLabel encryptType = new JLabel("加密类型");
        encryptType.setFont(new Font("宋体",5,20));
        encryptType.setSize(50, 100);
        JRadioButton encrypt_AES128 = new JRadioButton();
        encrypt_AES128.setSize(50,200);     con.add(encryptType);//把JLabel 组件添加到内容面板
        con.add(encrypt_AES128);//把JRadioButton 组件添加到内容面板     frame.setVisible(true);
        frame.setResizable(false);这样就可以了!!
    你所说的“为什么我设置它的位置,不移动?”我看不懂事什么意思,如果你是想把窗口显示出来的时候直接在屏幕中间的话,就把 frame.setBounds(300, 300, 600, 400)换成frame.setSize(600, 600)来设置大小,在 frame.setVisible(true)的前面加上frame.setLocationRelativeTo(null)来定位窗口显示在屏幕的中间。
      

  5.   

    package encryptview;import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.Font;import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;public class ViewDisplay extends JFrame{

    private JPanel panel;
    private JFrame frame;
    private JLabel encryptType,encryptKey,encrypt,undo;
    private JRadioButton encrypt_AES128;
    private JRadioButton encrypt_Base64;
    private JTextField encrypt_Key;
    private JTextArea encrypt_area1;
    private JTextArea encrypt_area2;
    private JButton button_encryot;
    private JButton button_undo;

    //提供一个构造器,以提升视图的初始化
    public ViewDisplay(){

    frame = new JFrame();
    panel = new JPanel();
    frame.setTitle("加密");
    frame.setBounds(300, 300, 600, 400);
    frame.add(panel);
    panel.setLayout(new FlowLayout());

    encryptType = new JLabel("加密类型:");
    encryptType.setFont(new Font("宋体",5,20));
    encryptType.setSize(50, 200);//这里的位置移动不了啊
    encrypt_AES128 = new JRadioButton();
    encrypt_AES128.setText("AES128");
    encrypt_AES128.setSize(50, 200);//这里的位置移动不了啊

    panel.add(encryptType);
    panel.add(encrypt_AES128);

    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    frame.setResizable(false);
    }
    }
    我上面标注的2个地方不是移动他在窗口中的位置吗?
    我怎么设置它的位置,他都是显示在最上面的中间。。为什么?