//如何不让按钮显示在中央,我的本意是希望从上至下显示!package com.woxiaoe.view;import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;import com.woxiaoe.view.util.GBC;public class ChatFrame extends JFrame{
private IhniClient ic;

private JToolBar toolBar;
private JTabbedPane tabbePane;
private JScrollPane friendsScrollPane,strangesScrollPane,bbsScrollPane;
private JPanel friendsPane,strangesPane,bbsPane;
public ChatFrame(IhniClient ic) {
this.ic = ic;
//this.setTitle(this.ic.getPerson().getName());
this.add(buildToolBar(),"North");
this.add(buildTabbePane());
setFriendsPane();
this.setSize(150, 400);
this.setVisible(true);
}
//设置工具条
public JToolBar buildToolBar(){
if(toolBar == null){
toolBar = new JToolBar();
JButton btn1 = new JButton("设置");
JButton btn2 = new JButton("查找");

toolBar.add(btn1);
toolBar.add(btn2);

}
return toolBar;
}
//设置面板
public JTabbedPane buildTabbePane(){
if(tabbePane == null){
tabbePane = new JTabbedPane(JTabbedPane.LEFT);
tabbePane.add("好友",buildFriendsScrollPane());
tabbePane.add("陌生人",buildStrangesScrollPane());
tabbePane.add("论坛",buildBbsScollPane());
}
return tabbePane;
}
public JScrollPane buildBbsScollPane(){
if(bbsScrollPane == null) {
bbsPane = new JPanel();
bbsPane.setLayout(new GridBagLayout());
bbsScrollPane = new JScrollPane(bbsPane,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

}
return bbsScrollPane;
}
public JScrollPane buildFriendsScrollPane(){
if(friendsScrollPane == null){
friendsPane = new JPanel();
friendsPane.setLayout(new GridBagLayout());



friendsScrollPane = new JScrollPane(friendsPane,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
}
return friendsScrollPane;

}
public JScrollPane buildStrangesScrollPane(){
if(strangesScrollPane == null){
strangesPane = new JPanel();
strangesPane.setLayout(new GridBagLayout());
strangesScrollPane = new JScrollPane(strangesPane,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
}
return strangesScrollPane;
}

public void setFriendsPane(){

JButton btn1 = new JButton();
btn1.setText("btn1");
GridBagConstraints gcb = new GridBagConstraints();
gcb.gridx = 0;
gcb.gridy = 0;
friendsPane.add(btn1,gcb /*GBC(0,0).setWeigth(0, 0)*/);
JButton btn2 = new JButton();
gcb.gridx = 0;
gcb.gridy = 1;
btn2.setText("btn2");
friendsPane.add(btn2,gcb);

}

public static void main(String[] args){
new ChatFrame(null).setVisible(true);
}
}