繁体   English   中英

JTabbedPane 直到我最小化 window 才显示

[英]JTabbedPane not showing until I minimize the window

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

public class ModuloAdministracion extends JFrame {

JTabbedPane tabbedPane;
JPanelProfesores jPanelProfesores;
JPanelCursos jPanelCursos;
JPanelAlumnos jPanelAlumnos;


public static void main(String[] args) {
    new ModuloAdministracion();
}

public ModuloAdministracion(){
    setInicio();
    tabbedPane=new JTabbedPane();

    jPanelProfesores=new JPanelProfesores();
    jPanelCursos=new JPanelCursos();
    jPanelAlumnos=new JPanelAlumnos();

    tabbedPane.setFont(new Font("Arial", Font.BOLD, 20));

    Color myColor=Color.decode("#345FE3");
    Color myColor2=Color.decode("#FBFCFC");

    tabbedPane.setBackground(myColor);
    tabbedPane.setForeground(myColor2);

    tabbedPane.add("Profesores", jPanelProfesores);
    tabbedPane.add("Cursos", jPanelCursos);
    tabbedPane.add("Alumnos", jPanelAlumnos);
    getContentPane().add(tabbedPane);
    tabbedPane.repaint();
}

public void setInicio(){
    setTitle("Modulo de administracion");
    setVisible(true);
    //setLayout(null);
    setLocation(125, 50);
    setSize(1100, 650);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setResizable(false);

}

public void addLabel(String titulo, int x, int y, int width, int height){
    JLabel anadirLabel=new JLabel(titulo);
    anadirLabel.setBounds(x,y,width,height);
    anadirLabel.setFont(new Font("Arial", Font.BOLD, 50));
    Color myColor = Color.decode("#345FE3");
    anadirLabel.setForeground(myColor);
    add(anadirLabel);
    repaint();
}

public void addLabel1(String titulo, int x, int y, int width, int height){
    JLabel anadirLabel=new JLabel(titulo);
    anadirLabel.setBounds(x,y,width,height);
    anadirLabel.setFont(new Font("Arial", Font.BOLD, 25));
    Color myColor = Color.decode("#FBFCFC");
    anadirLabel.setForeground(myColor);
    add(anadirLabel);
    repaint();
}

public JTextField addTextfield(String texto, int x, int y, int width, int height){
    JTextField txtUser=new JTextField(texto);
    txtUser.setBounds(x,y,width,height);
    txtUser.setFont(new Font("Arial", Font.PLAIN, 18));
    Color myColor = Color.decode("#1C2833");
    txtUser.setBackground(myColor);
    Color myColor2 = Color.decode("#FBFCFC");
    txtUser.setForeground(myColor2);
    add(txtUser);
    repaint();
    return txtUser;
}

public JPasswordField addPasswordField(String texto, int x, int y, int width, int height){
    JPasswordField passUser=new JPasswordField(texto);
    passUser.setBounds(x,y,width,height);
    passUser.setFont(new Font("Arial", Font.PLAIN, 18));
    Color myColor = Color.decode("#1C2833");
    passUser.setBackground(myColor);
    Color myColor2 = Color.decode("#FBFCFC");
    passUser.setForeground(myColor2);
    add(passUser);
    repaint();
    return passUser;
}

}

我一直在做一个项目,但我在JTabbedPane上遇到了一些问题,这对我来说是一个新组件。 我创建了单独的 windows,其中包含我的JPanel容器并添加了它们,但是当我运行程序时,它只显示一个空白 window,直到我单击最小化 window。 目前它不包含事件或做任何特别的事情,但我不知道为什么当我运行程序时它最初没有出现。

  1. 运行组件
  2. 最小化组件后
setInicio();

在使框架可见之前,需要将组件添加到框架中。

上面的代码需要移到构造函数的末尾。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM