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
的一些问题,这对我来说是一个新组件。我创建了包含我的 JPanel
容器的单独窗口,并添加了它们,但是当我运行程序时,它只显示一个空白窗口,直到我单击最小化窗口。目前它不包含事件或做任何特别的事情,但我不知道为什么当我运行程序时它最初没有出现。
答案 0 :(得分:1)
setInicio();
需要在框架可见之前将组件添加到框架中。
上面的代码需要移到构造函数的末尾。