正常代码段:
private void newJLabel() {
JLabel[] thum=new JLabel[12];
int line=1;
for(int i=1;i<=12;i++) {
thum[i-1]=new JLabel();
if(i%5==1) {
if(line==1) {
thum[i-1].setBounds(75*1, 50*line, 196, 282);
}else{
thum[i-1].setBounds(75*1, 50*line+282*(line-1), 196, 282);
}
}else if(i%5==2){
if(line==1) {
thum[i-1].setBounds(75*2+(296*1), 50*line, 196, 282);
}else {
thum[i-1].setBounds(75*2+(296*1), 50*line+282*(line-1), 196, 282);
}
}else if(i%5==3){
if(line==1) {
thum[i-1].setBounds(75*3+(296*2), 50*line, 196, 282);
}else {
thum[i-1].setBounds(75*3+(296*2), 50*line+282*(line-1), 196, 282);
}
}else if(i%5==4){
if(line==1) {
thum[i-1].setBounds(75*4+(296*3), 50*line, 196, 282);
}else {
thum[i-1].setBounds(75*4+(296*3), 50*line+282*(line-1), 196, 282);
}
}else if(i%5==0){
if(line==1) {
thum[i-1].setBounds(75*5+(296*4), 50*line, 196, 282);
}else {
thum[i-1].setBounds(75*5+(296*4), 50*line+282*(line-1), 196, 282);
}
}
if(i%5==0) {
line++;
}
thum[i-1].setOpaque(true);
thum[i-1].setIcon(new ImageIcon("src/thumbnails/0.jpg"));//问题在这里
thum[i-1].setVerticalAlignment(JLabel.TOP);
this.add(thum[i-1]);
}
}
zheng'chang'xian'shi'tu
异常代码段:
private void newJLabel() {
JLabel[] thum=new JLabel[12];
int line=1;
for(int i=1;i<=12;i++) {
thum[i-1]=new JLabel();
if(i%5==1) {
if(line==1) {
thum[i-1].setBounds(75*1, 50*line, 196, 282);
}else{
thum[i-1].setBounds(75*1, 50*line+282*(line-1), 196, 282);
}
}else if(i%5==2){
if(line==1) {
thum[i-1].setBounds(75*2+(296*1), 50*line, 196, 282);
}else {
thum[i-1].setBounds(75*2+(296*1), 50*line+282*(line-1), 196, 282);
}
}else if(i%5==3){
if(line==1) {
thum[i-1].setBounds(75*3+(296*2), 50*line, 196, 282);
}else {
thum[i-1].setBounds(75*3+(296*2), 50*line+282*(line-1), 196, 282);
}
}else if(i%5==4){
if(line==1) {
thum[i-1].setBounds(75*4+(296*3), 50*line, 196, 282);
}else {
thum[i-1].setBounds(75*4+(296*3), 50*line+282*(line-1), 196, 282);
}
}else if(i%5==0){
if(line==1) {
thum[i-1].setBounds(75*5+(296*4), 50*line, 196, 282);
}else {
thum[i-1].setBounds(75*5+(296*4), 50*line+282*(line-1), 196, 282);
}
}
if(i%5==0) {
line++;
}
thum[i-1].setOpaque(true);
thum[i-1].setIcon(new ImageIcon("src/thumbnails/"+i+".jpg"));//问题在这里
thum[i-1].setVerticalAlignment(JLabel.TOP);
this.add(thum[i-1]);
}
}
异常显示图