一个奇怪的问题,我把完整的代码贴出来了,请大家看看!
import java.awt.BorderLayout;import java.awt.Container;
import java.awt.Dimension;
import java.awt.List;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
public class PanelTest extends JFrame {
private JPanel listPanel;
private JScrollPane leftJScrollPanel;
private JScrollPane playJScrollPanel;
private List playList;
private List leftList;
private JSplitPane split;
private Container cp;
public PanelTest(){
init();
}
public void init(){
this.setSize(new Dimension(300, 379));
this.setTitle("PLAYER");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setResizable(false);
this.setLocation(200, 100);
this.setVisible(true);
}
public void lunchFrame(){
cp = getContentPane();
listPanel = new JPanel();
listPanel.setLayout(new BorderLayout());
//listPanel.setLayout(null);
//listPanel.setBounds(new Rectangle(4,150,289,148));
listPanel.setLocation(4, 150);
listPanel.setSize(new Dimension(289,148));
listPanel.setBorder(BorderFactory.createEtchedBorder());
leftList = new List();
leftJScrollPanel = new JScrollPane(leftList);
//leftJScrollPanel.setBounds(new Rectangle(4,150,100,148));
listPanel.add(leftJScrollPanel,BorderLayout.WEST);
playList = new List();
playJScrollPanel = new JScrollPane(playList);
//playJScrollPanel.setBounds(new Rectangle(100, 150, 189, 148));
listPanel.add(playJScrollPanel,BorderLayout.EAST);
split = new JSplitPane(SwingConstants.VERTICAL,true,leftJScrollPanel,playJScrollPanel );
split.setBorder(new EmptyBorder(0,0,0,0));
listPanel.add(split);
cp.add(listPanel);
}
public static void main(String args[]){
new PanelTest().lunchFrame();
}
}
运行起来很奇怪!左边会盯死!