我有这个功能,我收到String[][]
,f
(行)和c
(列)。我必须调整我的标签占据我的所有框架(1270,750)
。
例如,如果我收到:
f=3
和c=3
,图片将包含:(423.333,250.)
像素f=10
和c=10
,图片的像素数为(127,75)
。我已经证明了示例中的所有函数,但它不起作用。知道怎么做吗?
public void inicialitzamatriu(String[][] arraystrings,int f,int c) {
ff=f;
cc=c;
compsToExperiment=new JPanel();
GridLayout experimentLayout = new GridLayout(ff,cc);
compsToExperiment.setLayout(experimentLayout);
this.setContentPane(compsToExperiment);
for (int filas=0;filas<ff;filas++){
for (int columnas=0;columnas<cc;columnas++){
if (arraystrings[filas][columnas].equals("gat")){
JLabel cat2 = new JLabel();
cat2.resize(1270/cc, 750/cc);
cat2.setIcon(new ImageIcon("cat.png"));
compsToExperiment.add(cat2);
/*cat2.getSize();
//cat2.getWidth();
//cat2.getHeight();
cat2.resize(width, height);
cat2.setBounds(x, y, width, height)
cat2.setSize(width, height)
cat2.
*/
}
if (arraystrings[filas][columnas].equals("rat")){
JLabel rat2 = new JLabel();
rat2.setSize(1270/cc, 750/cc);
rat2.setIcon(new ImageIcon("raton.png"));
compsToExperiment.add(rat2);
}
if (arraystrings[filas][columnas].equals("menjar")){
JLabel comida2 = new JLabel();
comida2.setSize(1270/cc, 750/cc);
comida2.setIcon(new ImageIcon("comida.png"));
compsToExperiment.add(comida2);
}
if (arraystrings[filas][columnas].equals("res")){
JLabel nada2 = new JLabel();
nada2.setSize(1270/cc, 750/cc);
nada2.setIcon(new ImageIcon("nada.png"));
compsToExperiment.add(nada2);
}
}
}
this.repaint();
//compsToExperiment.repaint();
compsToExperiment.setVisible(true);
//this.setVisible(true);
//this.setVisible(false);
}