如何移动JTabbedpane

时间:2015-05-17 23:42:28

标签: java swing

我希望我的JTabbedpane位于panel3和panel4之上。 Rightnow,JTabbedpane位于panel1和panel2之上,但我希望它位于panel3和panel4之上。我尝试使用setBounds来降低JTabbedpane,但它不起作用。谢谢大家的帮助。

import java.awt.*;
import static java.awt.Font.BOLD;
import java.awt.event.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import javax.swing.*;
import static javax.swing.SwingConstants.CENTER;
import javax.swing.event.*;



public class hotels extends JFrame{

    JButton hotel;
    JLabel image;
     JTabbedPane tabbed,tabbed1;
    JPanel panel;
    JPanel panel1;

    Container pane;
    JPanel panel2;
    JPanel panel3;
    JPanel panel4;
    JLabel departure;
    JLabel from;
    JLabel to;
    JLabel searchflight,searchflight1;
    JButton back, back1;



    public hotels(){


         panel=new JPanel();
        panel.setBackground(Color.cyan);
        hotel=new JButton();
        hotel.setText("Hotels");

        Font myFont = new Font("Serif", Font.BOLD, 18);


        hotel.setFont(myFont);
        panel.setLayout(null);
        panel.add(hotel);

        hotel.setBounds(50, 80, 100, 40);


        image=new JLabel();

        image.setBounds(50,1,80,80);
        image.setBorder(BorderFactory.createLineBorder(Color.yellow));
        image.setBackground(Color.white);
        image.setIcon(new ImageIcon("2.gif"));
        panel.add(image);

       panel1=new JPanel();
        panel1.setLayout(null);
        panel1.setBounds(0, 30, 300, 400);

        back=new JButton();
        back.setText("<");
        back.setBounds(0, 5, 60, 30);
        panel1.add(back);

        searchflight=new JLabel();
        searchflight.setText("Search Flights");
        searchflight.setBounds(130,5,100,30);
        panel1.add(searchflight);
        tabbed=new JTabbedPane();
   tabbed.add( "Round Trip",panel1);



     panel2=new JPanel();
     panel2.setLayout(null);
     panel2.setBounds(0, 30, 300, 400);
     panel2.setBackground(Color.blue);

     searchflight1=new JLabel();
        searchflight1.setText("Search Flights");
        searchflight1.setBounds(130,5,100,30);
        panel2.add(searchflight1);

      back1=new JButton();
        back1.setText("<");
        back1.setBounds(0, 5, 60, 30);
        panel2.add(back1);


    panel4=new JPanel();
    panel4.setLayout(null);
    panel4.setBackground(Color.white);

     panel4.setBounds(0, 40, 290, 300);
     panel4.setBorder(BorderFactory.createMatteBorder(0, 10, 10, 10, Color.blue));


     Font f=new Font("Serif", Font.PLAIN,12);

       tabbed.add("One Way",panel2);

          panel3=new JPanel();
     panel3.setBounds(0, 40, 290, 300);
    panel3.setLayout(null);

    panel3.setBorder(BorderFactory.createMatteBorder(0, 10, 10, 10, Color.blue));
    panel3.setBackground(Color.white);

    panel1.add(panel3);

     panel2.add(panel4);


       from=new JLabel();
       from.setBackground(Color.blue);

       panel1.setBackground(Color.blue);



        pane=getContentPane();


          pane.add(panel);


   image.addMouseListener(new MouseAdapter()

   {

      public void mouseClicked(MouseEvent e){
           if (e.getSource()==image){

      pane.removeAll();

      pane.add(tabbed);
      pane.revalidate();
      pane.repaint();


           }


       }


   }


   );

    }



    public static void main(String[] args) {

 hotels mw=new hotels();
  mw.setVisible(true);
  mw.setSize(300, 400);
  mw.setResizable(false);


    }



    }

0 个答案:

没有答案