把frame的风格改一下,改成xy的那种,label想放哪就放哪

解决方案 »

  1.   

    别用xylayout,因为你要带jbcl,layout设为null替代xylayout.
    你的问题还可以一种方法。
    整个panel设为borderlabyout.再其中加一个JPanel到borderlayout的south,再设此JPanel的layout为borderlayout,加你的label到其中的east一块。
      

  2.   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class Frame1 extends JFrame {
        private JPanel contentPane;
        private BorderLayout borderLayout1 = new BorderLayout();
        private JPanel jPanel1 = new JPanel();
        private BorderLayout borderLayout2 = new BorderLayout();
        private JLabel jLabel1 = new JLabel();    //Construct the frame
        public Frame1() {
            enableEvents(AWTEvent.WINDOW_EVENT_MASK);
            try {
                jbInit();
            }
            catch(Exception e) {
                e.printStackTrace();
            }
        }
        //Component initialization
        private void jbInit() throws Exception  {
            contentPane = (JPanel) this.getContentPane();
            contentPane.setLayout(borderLayout1);
            this.setSize(new Dimension(400, 300));
            this.setTitle("Frame Title");
            jPanel1.setLayout(borderLayout2);
            jLabel1.setText("MyLabel");
            contentPane.add(jPanel1,  BorderLayout.SOUTH);
            jPanel1.add(jLabel1,  BorderLayout.EAST);
        }
        //Overridden so we can exit when window is closed
        protected void processWindowEvent(WindowEvent e) {
            super.processWindowEvent(e);
            if (e.getID() == WindowEvent.WINDOW_CLOSING) {
                System.exit(0);
            }
        }    public static void main(String[] args) {
            Frame1 frame = new Frame1();
            frame.validate();
            frame.setVisible(true);
        }
    }