Thanks, that was just a tiny portion of what is really going on, if you
insist. I was hoping it would be simplier with the problem stripped
out.
public void jButton1_actionPerformed(ActionEvent e) {
GetThumb(this.jLabel1, this.jTextField1, 1);
}
public void GetThumb(JLabel labelNo, JTextField fieldNo, int k) {
JFileChooser choose = new JFileChooser();
choose.addChoosableFileFilter(new ImageFilter());
choose.setAcceptAllFileFilterUsed(false);
//choose.setFileView(new ImageFileView());
choose.setAccessory(new ImagePreview(choose));
choose.setVisible(true);
int returnVal = choose.showDialog(this, "Select a Image");
if (choose.getSelectedFile() != null) {
if (returnVal == JFileChooser.APPROVE_OPTION) {
//fieldNo.setText(choose.getSelectedFile().getAbsolutePath());
String name =
choose.getSelectedFile().getAbsolutePath();
///added by bbb
int t = 100; //thumbnail size
ImageIcon thumbnail = null;
ImageIcon tmpIcon = new ImageIcon(name);
if (tmpIcon.getIconWidth() > t) {
//get image ratio
int imageWidth = tmpIcon.getIconWidth();
int imageHeight = tmpIcon.getIconHeight();
//scaling
double scaleX = t / (double) imageHeight;
double scaleY = t/ (double) imageWidth;
double scale = Math.min(scaleX, scaleY);
// Determine size of new image.
int w = (int) (scale * imageWidth);
int h = (int) (scale * imageHeight);
//needs scaling
if ((imageWidth > t)||(imageHeight >t)) {
// try {
// java.net.InetAddress localMachine =
java.net.InetAddress.getLocalHost();
//
fieldNo.setText(String.valueOf(localMachine));
// } catch (java.net.UnknownHostException uhe) {
// [beware typo in code sample - dmw]
// // handle exception
// }
fieldNo.setText(name);
imgsrc[k] =
choose.getSelectedFile().getAbsolutePath();
imgname[k] =
choose.getSelectedFile().getName();
thumbnail = new ImageIcon(tmpIcon.getImage().
getScaledInstance(w,
h,
Image.SCALE_DEFAULT));
} else {
//fieldNo.setText(String.valueOf(imageRatio));
imgsrc[k] =
choose.getSelectedFile().getAbsolutePath();
imgname[k] = choose.getSelectedFile().getName();
fieldNo.setText(name);
thumbnail = new ImageIcon(tmpIcon.getImage().
getScaledInstance(w,
h,
Image.SCALE_DEFAULT));
}
} else {
thumbnail = tmpIcon;
}
JOptionPane.showMessageDialog(this,"FieldNo:"+fieldNo.getName()+"ImageNo:"+labelNo.getName(),
"",
JOptionPane.ERROR_MESSAGE);
labelNo.setIcon(thumbnail);
}
}
}
> > I'm try to use a function to set some text and set the icons of various
> > labels and I thought I could send the labelnames to the function and
[quoted text clipped - 26 lines]
>
> - Oliver
Oliver Wong - 07 Jun 2006 22:04 GMT
[post re-ordered]
>> Aside from that, there isn't much help that can be provided to you,
>> because you have posted enough code. For example, the variable
[quoted text clipped - 5 lines]
> insist. I was hoping it would be simplier with the problem stripped
> out.
[code snipped]
The code you provided still doesn't compile. You've got methods just
floating around, instead of within a class.
Also, don't use line comments (the ones that start with //) in code you
post to newsgroup, because the word wrapping will cause confusion as to
which lines are commented out and which aren't.
Finally, don't forget to actually trim down your code to the minimum
which actually demonstrates your problem. I don't think the line that starts
with "JOptionPane.showMessageDialog" has anything to do with your labels
getting random values in them, for example. Re-read
http://mindprod.com/jgloss/sscce.html
- Oliver
Barkster - 07 Jun 2006 22:31 GMT
I'm not posting my whole project, the questions was pretty clear I
thought, Oh well, I'm looking at my process not if it compiles. I need
to know if I am passing labels to the function correctly or not. I
don't have any other problems except that, I don't think my other code
is the issue but you never know.
> [post re-ordered]
>
[quoted text clipped - 24 lines]
>
> - Oliver