![](/img/trans.png)
[英]JComponents don't appear until mouseover or I minimize the window, and JTextField problems
[英]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。 目前它不包含事件或做任何特別的事情,但我不知道為什么當我運行程序時它最初沒有出現。
setInicio();
在使框架可見之前,需要將組件添加到框架中。
上面的代碼需要移到構造函數的末尾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.