日期:2014-05-20  浏览次数:20628 次

JTabbedPane的问题
JTabbedPane   tabbedPane   =   new   JTabbedPane();

        JPanel   panel1   =   new   JPanel();

        JTextArea   area1   =   new   JTextArea(50,   50);  
       
        area1.setEditable(false);
       
        panel1.add(area1,   BorderLayout.CENTER);
       
        tabbedPane.addTab( "Tab   one ",   null,   panel1,   "First   Panel ");
该代码就是实现了将一个area1添加到panel1,再将panel1添加到tabbedPane中,请问能不能让area1的大小随着窗口的大小能自动的变大或缩小。
这个不会,请大家帮忙看看,谢谢!

------解决方案--------------------
把那几个panel都设成BorderLayout

panel1.setLayout(new BorderLayout());
panel2.setLayout(new BorderLayout());
panel3.setLayout(new BorderLayout());

是不是你要的效果
------解决方案--------------------


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Screen extends JFrame {
private static final long serialVersionUID = 41L;

public Screen() {
super( "DataBase System ");

JMenu fileMenu = new JMenu( "系统 ");
fileMenu.setMnemonic( 'S ');

JMenuItem startServer = new JMenuItem( "启动服务器 ");
startServer.setMnemonic( 'T ');
fileMenu.add(startServer);
startServer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
// 启动服务器方法;
}
});

JMenuItem connectServer = new JMenuItem( "连接服务器 ");
connectServer.setMnemonic( 'C ');
fileMenu.add(connectServer);
connectServer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
JOptionPane.showInputDialog( "服务器名或者服务器IP: ");
}
});

JMenuItem excute = new JMenuItem( "执行SQL语句 ");
excute.setMnemonic( 'E ');
fileMenu.add(excute);
excute.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
// 运行方法;
}
});

JMenuItem exit = new JMenuItem( "退出 ");
exit.setMnemonic( 'X ');
fileMenu.add(exit);
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.exit(0);
}
});

JMenuBar bar = new JMenuBar();
setJMenuBar(bar);
bar.add(fileMenu);

JMenu aboutMenu = new JMenu( "关于 ");
aboutMenu.setMnemonic( 'A ');

JMenuItem group = new JMenuItem( "小组成员 ");
group.setMnemonic( 'G ');
group.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
String groupName = "333 " + " 33\n " + "333 "
+ " 33\n " + "333 " + " 33\n ";
JTextArea textArea = new JTextArea();
textArea.setEditable(false);
textArea.setText(groupName);

JOptionPane.showMessageDialog(null, textArea, "小组成员 ",
JOptionPane.INFORMATION_MESSAGE);
}
});

aboutMenu.add(group);
bar.add(aboutMenu);

JTextArea outputArea = new JTextArea();

JTabbedPane tabbedPane = new JTabbedPane();