问题描述
- java的setlayout(null),选项卡组件不显示
-
我这里有一个继承jpanel的类
其中setlayout(null),我添加了一个跑马灯的组件和一个选项卡组件,并且我都用了setbounds,可是我的跑马灯能够正常显示而选项卡不能显示如果把setlayout删除则跑马灯和选项卡都能显示出来,可是这时候的位置是固定的无法进行修改我把代码拷贝一下请大神们修改一下,谢谢
package gui.logon;import gui.frame.SystemFrame;
import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.GeneralPath;
import java.text.SimpleDateFormat;
import java.util.BitSet;
import java.util.Date;import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;import action.ActionBean;
import action.ActionMessage;
import actions.EnterButtonAction;
import beans.Student;// 登录Panel类
public class LogonPanel extends JPanel {
private static final long serialVersionUID = -4614980225785032078L;private JTabbedPane tabs; //选项卡
private Marque marque;
private Container getContentPane;
public LogonPanel() {
this.init();
this.addComponent();
}
//初始化
public void init() {
this.setOpaque(false);
}
//添加跑马灯选项卡等方法
public void addComponent(){
this.add(this.test());//加载跑马灯
for(JTabbedPane tabs:this.tabs()){
this.add(tabs);//加载选项卡
}
}//跑马灯方法
public Marque test(){
Marque test = new Marque();
test.setBounds(0,60,450,20);
return test;
}
//选项卡列表
public JTabbedPane[] tabs(){
JPanel LogonUsePanel = new JPanel();
JPanel RegisterAccountPanel = new JPanel();
JPanel Accountbinding = new JPanel();
JPanel AccountRecharge = new JPanel();
JPanel Accountmodification= new JPanel();
JTabbedPane tabs = new JTabbedPane();
tabs.addTab("登录使用",LogonUsePanel);
tabs.addTab("注册账户",RegisterAccountPanel);
tabs.addTab("账户绑定",Accountbinding);
tabs.addTab("账户充值",AccountRecharge);
tabs.addTab("账户改密",Accountmodification);
this.add(tabs);
Container container = new Container();
this.setBounds(0,81,450,20);
return new JTabbedPane[] {tabs};
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(new ImageIcon("src/images/logon.png").getImage(), 0, 0, null);
}}
解决方案
http://bbs.csdn.net/topics/350034629