Java 我试图将JPanel添加到GridbagLayout中,但它们没有';不出现
这是代码Java 我试图将JPanel添加到GridbagLayout中,但它们没有';不出现,java,swing,layout-manager,gridbaglayout,Java,Swing,Layout Manager,Gridbaglayout,这是代码 public class Habitacion extends JFrame{ ArrayList <JButton> botones=new ArrayList(); ArrayList<ascensor> ascensores=new ArrayList(); boolean ban=true; int numeroX=0; int numeroY=0; int i=0,j=0,k=0; JPanel
public class Habitacion extends JFrame{
ArrayList <JButton> botones=new ArrayList();
ArrayList<ascensor> ascensores=new ArrayList();
boolean ban=true;
int numeroX=0;
int numeroY=0;
int i=0,j=0,k=0;
JPanel botonesPanel;
JPanel panelAscensores;
public Habitacion(){
//JFrame ventana = new JFrame();
this.setTitle("ascensor");
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
this.setSize(1366,768);
this.botonesPanel= new JPanel(new GridLayout(8, 1));
this.panelAscensores= new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
for(i=0;i<8;i++){
numeroX=0;
for(j=0;j<10;j++){
if(ascensores.size()!=10){
ascensores.add(new ascensor(5+numeroX,20+numeroY));
c.fill = GridBagConstraints.CENTER;
c.gridx = j;
c.gridy = 0;
this.panelAscensores.add(ascensores.get(j), c);
ascensores.get(j).setBounds(0+numeroX,0,100,720);
}
this.setLayout(new BorderLayout());
this.add(botonesPanel,BorderLayout.EAST);
this.add(panelAscensores,BorderLayout.CENTER);
}
公共类Habitacion扩展JFrame{
ArrayList botones=新的ArrayList();
ArrayList Ascensors=新的ArrayList();
布尔ban=true;
整数=0;
整数=0;
int i=0,j=0,k=0;
JPanel botonesPanel;
JPanel PanelAscensors;
公共住宅({
//JFrame ventana=新JFrame();
本条。设定标题(“上升者”);
此.setLayout(null);
此.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
此参数为.setresizeable(false);
此.setSize(1366768);
this.botonesPanel=newjpanel(newgridlayout(8,1));
this.panelAsSensors=newJPanel(newGridBagLayout());
GridBagConstraints c=新的GridBagConstraints();
对于(i=0;iPaste您的完整类代码,当前代码没有意义GridBagConstraints
与Assensors.get(j).setBounds(0+numeroX,0100720);
,必须决定是GBC还是NullLayoututand谈论GridBagouts的想法要想尽快得到更好的帮助,请发布一条。请减少“完整代码”(或任何乱七八糟的东西)降到一个SSCCE。
public class ascensor extends JPanel implements Runnable{
public int posX,y,newY,puertaDer,puertaIzq;
//MiMouseAdapter e=new MiMouseAdapter();
Thread hilo;
boolean ban=true;
public ascensor(int posX,int posY){
this.posX=posX;
this.y=posY;
this.newY=posY;
puertaDer=posX;
puertaIzq=posX+40;
hilo=new Thread(this);
}
@Override
public void run() {
int numero=0;
Boolean bandera=true;
while(true){
while(bandera){
if(newY < y)
numero=-1;
else
numero=1;
System.out.println(y);
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
}
y=y+numero;
if(y==newY)
hilo.suspend();
repaint();
}
System.out.println("posicion Y:");
System.out.println(newY);
repaint();
}
}
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D pluma=(Graphics2D)g;
g.drawRect(posX,newY+10,40, 50);
pluma.setColor(Color.red);
pluma.drawLine(puertaDer, 10+newY, puertaDer, 60+newY);
pluma.drawLine(puertaIzq, 10+newY,puertaIzq, 60+newY);
}
}
}