Re: Display Icon from path
Quote:
do I String Path set for Master table elements or to make it difrante?
Could you explain what this means? Especially the last word: difrante.
Re: Display Icon from path
Quote:
Originally Posted by
Norm
Could you explain what this means? Especially the last word: difrante.
First sorry my English is quite bad. That word should be "A different"
I mean how to display image into Jlabel from master table path ( cell what have path in it ). I have used a ActionListener to display a Image into application but that is not what I am looking for.
Re: Display Icon from path
Sorry I don't know what you mean by "master table path".
There are several basic ways of getting the data from a image file to create an Image object:
Use a File object
or use an InputStream
or Use a URL to a resource.
There are different versions of the ImageIO read method that you can use to read the image file depending on where it is and how you are accessing it.
I don't know that an ActionListener would be involved in reading an image.
Re: Display Icon from path
I have mean as "Master Table Path" that is a colum in the table what have a URL to image.
Yea i see now that code what i posted is not eaven close what i need. I am currently searching to see how to get URL to JTextField whit Jfilechooser. And icon should be reading URL from JtextField and display at APP when i select a row at the table.
My post looking like ape was try to explain. Sorry on that aswell.
Re: Display Icon from path
Do you have new code that shows the problem?
Re: Display Icon from path
No, I am still looking for that what I write on last post. I got only Jfilechooser but still not get after that. I will try to make new code to work. Then I can post code. But for now is reading a lot of page's.
This is what i have made. In gui added a button, below a jtextfield, on button added a actionlistener.
Code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String filLocation = null;
JFileChooser fchoose = new JFileChooser(filLocation);
int ff = fchoose.showOpenDialog(null);
if (ff == JFileChooser.APPROVE_OPTION) {
filLocation = fchoose.getSelectedFile().getParent();
File selectedPfile = fchoose.getSelectedFile();
myJTextField.setText(selectedPfile.getAbsolutePath());
}
setSaveNeeded(true);
}
Now I will try to edit a jlabel to read a JtextField in code above named myJTextField and to display as icon at application.
Re: Display Icon from path
Okey i am officialy stuck.
I got jtextfield whit path, but i dont know how to send to Jlabel to be a Icon. How to String text = textField.getText(); jlabel to read as path and display it?
Re: Display Icon from path
Do you have a String that contains the path to the file?
Given that String, you can use the ImageIcon class's constructor to load/read the image.
Then use that ImageIcon object with a method in the JLabel class to set its icon.
Re: Display Icon from path
I am working in netbeans, So I have to edit code like this one jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/me/myimageapp/resources/park-sculpture.jpg"))); // NOI18N
So i need to write all that whitin a code or make some other way. And i dont know wher and how to start it? Fist to get text form textfield and turn in it into a String and then send as path?
Realy dont know how to do that.
Re: Display Icon from path
Quote:
get text form textfield and turn in it into a String and then send as path?
You need to read the API doc for each of the classes you are working with to find the method to use.
The API doc for the classes is here:
Java Platform SE 6
Find the class in the lower left, click on it and the doc shows in the main frame.
Re: Display Icon from path
Netbeans should have nothing to do with it, unless you are using the GUI builder, in which case I would say STOP, because you clearly don't know enough to be doing that.
Norm has told you how to get an ImageIcon, and what constructor to use...
Re: Display Icon from path
How I see it I need to write within icon to read a path and display it, and if is null to display a default Image.
I will dig in it this link what you give me. Blargh so, reading for several hours.
Quote:
Netbeans should have nothing to do with it, unless you are using the GUI builder, in which case I would say STOP
To late, I will doo the reading then try to implement in it.
Re: Display Icon from path
Again me, i got working on my problem i make several way to approach but i dont know when I am making mistake.
Netbeans generated code is this ( i have edit to getResource )
Code:
Jico.setIcon(new javax.swing.ImageIcon(getClass().getResource(path)));
Added custom code above generated block,
Code:
private URL getResource(String Path) throws IOException {
{
String Path = fdField.getText();
BufferedImage image = ImageIO.read(new File(Path));
int type = image.getType() == 0? BufferedImage.TYPE_INT_ARGB : image.getType();
BufferedImage resizedImage = new BufferedImage(Jico.getWidth(), Jico.getHeight(), type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(image, 0, 0, Jico.getWidth(), Jico.getHeight(), null);
g.dispose();
Jico.setIcon(new ImageIcon(resizedImage)); }
}
problem is in second row "String Path = fdField.getText();" give me a error path is already defined in getResource(java.lang.string)
Re: Display Icon from path
You have the variable path define in two places:
Code:
private URL getResource(String Path) throws IOException {
{
String Path = fdField.getText();
Should one of them be renamed?
Re: Display Icon from path
Quote:
"String Path = fdField.getText();" give me a error path is already defined in getResource
It is too. That's the name you gave to the parameter to the method.
Quote:
private URL getResource(String Path)
Also, learn to respect Java coding conventions: variable names start with a lowercase letter.
Code Conventions for the Java(TM) Programming Language: Contents
db
Re: Display Icon from path
Something i mess up, i was try to doo this
Quote:
Originally Posted by
Norm
Do you have a String that contains the path to the file?
Given that String, you can use the ImageIcon class's constructor to load/read the image.
Then use that ImageIcon object with a method in the JLabel class to set its icon.
Thinking that i am mix several things, must doo more of defining code for that.