[英]How to see JLabel Array in JPanel
This is my click action:这是我的点击操作:
succ.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
int x=0;
int i;
labelpanel.revalidate();
labelpanel.repaint();
for (i=status; i<status+5; i++){
RidimIcon locand = new RidimIcon();
labelapp.get(i).setBounds(74+x, 1, 80, 90);
labelapp.get(i).setIcon(locand.newicona(pathicon[i], labelapp.get(i)));
labelpanel.add(labelapp.get(i));
x=x+120;
}
status=status+5; //change status
}
});
"Labelpanel" is an array of JLabel: "Labelpanel" 是一个 JLabel 数组:
try {
ResultSet rs = Datainter.eseguiQuery(query);
while(rs.next())
{
pathicon[contatore] = rs.getString("locandina");
JLabel tmplabel = new JLabel();
labelapp.add(tmplabel);
labelapp.get(contatore).setIcon(new ImageIcon(pathicon[contatore]));
contatore++;
}
} catch (SQLException e) {
e.printStackTrace();
}
i want to create programm that see 5 image at click.我想创建一个在点击时看到 5 个图像的程序。 I have an array labels with 50 images, when i click first time i see 1 - 5 labels[1-5], when i click second time i see labels[5-10], third time [10-11] etc.. Why i see only first 5 labelapp when i click on "succ"?
我有一个包含 50 个图像的数组标签,当我第一次点击时我看到 1 - 5 个标签 [1-5],当我第二次点击时我看到标签 [5-10],第三次 [10-11] 等等。为什么当我点击“succ”时我只看到前 5 个 labelapp? How can i see other 5 labelapp when i click again and leave first 5 images in panel?
当我再次单击并在面板中保留前 5 个图像时,我如何才能看到其他 5 个 labelapp?
(with RemoveAll i cant see my last Jlabels: (使用 RemoveAll 我看不到我最后的 Jlabels:
prec.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int x=0;
int i;
labelpanel.removeAll();
for (i=status; i<status-5; i--){
RidimIcon locand = new RidimIcon();
labelapp.get(i).setBounds(74+x, 1, 80, 90);
labelapp.get(i).setIcon(locand.newicona(pathicon[i], labelapp.get(i)));
labelpanel.add(labelapp.get(i));
x=x+120;
}
labelpanel.revalidate();
labelpanel.repaint();
status=status-5;
}
});
Use removeAll()
to remove all previous labels from the labelPanel
.使用
removeAll()
从labelPanel
删除所有以前的标签。 Then add new labels and call revalidate()
and repaint()
.然后添加新标签并调用
revalidate()
和repaint()
。
public void mouseClicked(MouseEvent arg0) {
int x=0;
int i;
labelpanel.removeAll();
for (i=status; i<status+5; i++){
RidimIcon locand = new RidimIcon();
labelapp.get(i).setBounds(74+x, 1, 80, 90);
labelapp.get(i).setIcon(locand.newicona(pathicon[i], labelapp.get(i)));
labelpanel.add(labelapp.get(i));
x=x+120;
}
labelpanel.revalidate();
labelpanel.repaint();
status=status+5; //change status
if(status > 17) {
status = 17;
}
}
And some advices;以及一些建议;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.