Swing/AWT/SWT :: Loading Image From Relative Path

Mar 15, 2015

All I want to do is load an image into a swing JLabel and display it, but I'm going to have to make a JAR of the program and submit it for grading, so I need to be able to get the path of the image file relative to the JAR (at least I think that's how it works - I've never made a JAR before. Right now I'm just trying to load it from a path relative to my netbeans project). I've tried at least 20 different combinations of paths, file locations within the project, etc., but nothing works.

Anyways, here's the test class I've been using to try to figure this out in its current iteration. Right now the image I want to load is in src/resources and the class is in

src/imagedisplaytest
package imagedisplaytest;
import javax.swing.*;
import java.awt.*;
public class ImageDisplayTest extends JFrame {
private JLabel testLabel;
public ImageDisplayTest()

[Code]...

What's the best way to do this?

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Getting Images From Folder Inside Project - Relative Path

Jul 17, 2014

I'm going through the next problem:

importing a project from Eclipse into NetBeans, I tried importing project, did not work, anyway

I got all the classes good, but I got a folder with images and a TXT file

part of the code:

listaIconsPlayers[0]=(IconsUtils.makeIcon("imagespinspin_blue.png",dimensaoPinGrande,"pin_blue"));
listaIconsPlayers[1]=(IconsUtils.makeIcon("imagespinspin_green.png",dimensaoPinGrande,"pin_green"));
listaIconsPlayers[2]=(IconsUtils.makeIcon("imagespinspin_purple.png",dimensaoPinGrande,"pin_purple"));
listaIconsPlayers[3]=(IconsUtils.makeIcon("imagespinspin_red.png",dimensaoPinGrande,"pin_red"));
listaIconsPlayers[4]=(IconsUtils.makeIcon("imagespinspin_yellow.png",dimensaoPinGrande,"pin_yellow"));

Where do I place my folder Images and how can I configure this so this lines of code go get that images from a folder inside the project..

View Replies View Related

Use Relative Path In Place Of Absolute Path

Nov 7, 2014

I am copying the xml files from one folder to other folder, in the source folder, i have some files which have some content like "backing File="$IDP_ ROOT/metadata/iPAU-SP-metadata.xml" but while writing to the destination folder.i am replacing the "$IDP_ROOT" with my current working directory. The entire copying of files is for deploying into tomcat server. The copying is done only when server starts for the first time.Problem: If i change the folder name from my root path in my machine after i run the server,the entire process will be stopped because the destination folder files already contains the content which is with existed files names or folder names.

So i want to change it to relative path instead absolute path. What is the best way to do it? Please look at code below:

[ // Getting the current working directory
String currentdir = new File(".").getAbsoluteFile().getParent() + File.separator;

if(currentdir.indexOf("ControlPanel")!=-1){
rootPath=currentdir.substring(0, currentdir.indexOf("ControlPanel"));
}else{
rootPath=currentdir;

[code]....

View Replies View Related

Swing/AWT/SWT :: Why Isn't Image Loading

Jun 20, 2014

I have added the image in the src and bin directories and cross-checked that the name of the image file is correct..Here is the main class

import javax.swing.*;
public class apples
{
public static void main(String args[])
{
JFrame frame = new JFrame();
MyDrawPanel wid = new MyDrawPanel();
frame.add(wid);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(300,300);
}
}

and here is the class that does the image adding part

import java.awt.*;
import javax.swing.*;

public class MyDrawPanel extends JPanel
{
public void paintComponent(Graphics g)
{

Image image = new ImageIcon("b.png").getImage();
g.drawImage(image,20, 20, this);
}
}

View Replies View Related

Relative Path Not Working

Sep 11, 2014

relative path not working if specified folder is outside eclipse IDE, but if i put same folder in current project it is working.

View Replies View Related

Swing/AWT/SWT :: Loading Image File From Source Directory?

Jan 25, 2014

My problem is that I want to load an Image from the source directory in Canavas' paint() method.

My code is currently (in a try/catch)

g.drawImage(ImageIO.read(new File(imageLocation)), imageX, imageY, null);

Where imageLocation leads to an image on my HDD ("C:UsersVladdeDocumentsFolders-Filesfolder.png")

View Replies View Related

Servlets :: Relative Or Absolute Path

Feb 14, 2014

Is /graphics/image.png a relative path or absolute path?

View Replies View Related

JavaFX 2.0 :: Native Package For Mac And Relative Path

Dec 3, 2014

I done a small application with Javafx that start an Embedded Jetty. All works fine in Windows also with native package. Instead in Mac it works only before native packaging. Seems that the problem is how relative path are considered.
 
The tree of the content is this:
myfile.jar
webapp (folder)
libs (folder)
 
Look at this code:
 
                String webAppDir = "webapp";
                File f = new File(webAppDir);
                log.debug("Path webapp folder: " + f.getAbsolutePath());
                if (!f.exists())
                    throw new Exception("The folder " + f.getAbsolutePath() + " doesn't exist");

[Code] .... 

The problem is that before the packaging in Mac the relative path is that where the main .jar is located an so the code works because the webapp folder is found. Instead after the bundle the path became /Users/MyUser/webapp and of course the folder is not found because it is bundled inside the file.app near the libs folder.

View Replies View Related

Getting Correct Path When Making ImageIcon - Loading Images To Eclipse

Aug 21, 2014

I am having trouble getting the correct path when making ImageIcon ( i1 ,i2, i3, i4) . I have tried

(this.getClass().getResource("/image/1.png"));
("image/ca.gif");
and
("Users/aritime/Documents/src/ca.gif ");

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
public class myImageIcon extends JFrame{

[Code] ....

View Replies View Related

JSF :: How To Read CSV File From User Defined Directory Path For Loading To Managed Bean

Jan 10, 2015

I'm using a PrimeFaces UploadedFile xhtml page to select a csv file to read and write using a managed bean (SuperCSVParser.java). The file is read and written to an entity class which then persists the data to a database. The application works fine if I specify a file path on the physical server and select a csv file on that file path. But for the production version I want the user to select ANY file name from ANY directory on their local system.

I know about the FacesContext methods and I've looked at some methods from the java.io File class. Most of these methods are about getting the path from the server, where I want to 'pass' the path String from the client machine to allow the uploaded file to go through. When I try with the below code I get:

java.io.FileNotFoundException: data.csv (The system cannot find the file specified)

I'd like to know what I'm doing as I prefer not to explicitly declare a path in the final app. I'm almost sure that's possible.

<h:form enctype="multipart/form-data">
<p:fileUpload value="#{SuperCsvParser.file}"
mode="simple"
auto="true"

[Code].....

View Replies View Related

JSP :: How To Show Loading Image

Feb 11, 2014

I have to show a loading image which should tell some proper loading message in jsp.

View Replies View Related

Image Loading In Java Using HTML

Apr 9, 2015

I want to load image in java using Html. it works in neatbeans. But if i create a jar file it not load

URL url = getClass().getClassLoader().getResource("http://www.javaprogrammingforums.com/images/sms.png");
String tab= "<html><table style='width:100%; table-layout:fixed'><tr><td style='width: 30px' rowspan=2 >
<img src='"+ url+ "' width=36 height=36/></td><td font color='#ffffff' style='width: 110px'><font size='4'>
"+namePerson+"</font></td><td font color='#ffffff'>"+myDate+"</td></tr> <tr>
<td font color='#ffffff' style='width: 110px'>"+str1+"</td></tr></table></html>";

jLabel1.setIcon(new ImageIcon(url));// it works
tmodel.addRow(new Object[] {tab}); // not works why

not work in jar file..

View Replies View Related

Loading Multiple Image Icons

Aug 17, 2014

import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
public class Golf extends JFrame
{
boolean isRunning = true;

[Code] ....

It loads and draws fine when I am using one image. But if I un-comment the others are try to draw the background of my game as intended, nothing gets drawn. I've played around with a number of different solutions but nothing works, I've had multiple images work in previous programs doing exactly the same thing and I really don't understand whats up.

View Replies View Related

JSP :: Choose / Display Image Path

Mar 15, 2014

I want to do the followings:

-When i press "choose the Image Path" a window open like a picture 2.
-I want also satisfy the condition written in red.

View Replies View Related

Image Path Java To Exe / Jar File

Sep 30, 2014

I already done my program with images on it but when i convert it to exe , the images is not appearing.

Usually my images are located at documents netbeansprojectprojectimage.jpg

When i run the code on netbeans the images are appearing but when i convert it to exe or jar file run on a computer without netbeans.. images is not appearing ...

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.ImageIcon;

class Phonebook extends JFrame {
private static final int WIDTH = 430;
private static final int HEIGHT = 200;
public Phonebook()

[Code] ....

View Replies View Related

Drawing Image - Specify File Path

Jul 3, 2014

Gyazo - e5663e8da42ac46a642895d72836b933.png

As you can see I have specified a file path, as it is needed to draw the image.

The image "sun" is in a certain folder inside the directory of my jar file.

But If I were to send the whole package to my teacher to review. The file path would still remain the same, local to my computer making the image, unloadable.?

View Replies View Related

Swing/AWT/SWT :: Saving And Loading Data Of Jtable

Apr 6, 2015

I am trying to make a program where a user can enter guests name for a hotel, the JTable includes rows for the name of the tenant, the room number, month etc.

I've made the table, however I am having some trouble in saving the data that I put into the table. I used jtextfield and a jbutton to but data into the jtable. I am trying to save the data, and load it just buy clicking a button.

table.setModel(new DefaultTableModel(
new Object[][] {
},
new String[] {
"Room", "Name", "Month", "Payment"//table rows
}
));

This is my basic table. And what I'm trying to do to save the data is:

DefaultTableModel model = new DefaultTableModel();
private JFileChooser myJFileChooser = new JFileChooser(new File("."));
private void saveTable() {
if (myJFileChooser.showSaveDialog(null) ==
JFileChooser.APPROVE_OPTION ) {
saveTable(myJFileChooser.getSelectedFile());

[Code] ....

When I run my program, I'm able to click on a button, and the dialog box will appear, I'm also able to save the data to a file. However when I click on the retieve data button I made the dialog box opens, the file is there, however when I click it, nothing happens.

View Replies View Related

Swing/AWT/SWT :: Image Manipulation - Create Application Where Image Is Displayed On One Label

Apr 7, 2014

Sir, I'am new to Swing Programming. I have to create an application where an image is displayed on one Label. The same image has to be split in parts and stored in database pert wise. Later the user has to retrieve the entire image by viewing a small part of the image. I have already displayed the full image on the Label, now i don't know how to split the image and store it part wise in the database.

View Replies View Related

Swing/AWT/SWT :: Loading SVG Images On JPanel With Transparent Background

Mar 27, 2014

I'm working on loading SVG images on Jpanel using "Apache(tm) Batik SVG Toolkit" , but after the image get loaded it has "white background" and "not transparent" one like PNG images.

I checked "fill" of rect attribute on the xml file of the svg image and it was correctly set to none, I also Tested the image on html document and it was trasparent, but in my java app it has white background.

The Question is there any way to load SVG images with transparent background on Jpanel ?

View Replies View Related

Can't Get Relative Paths To Work

Apr 25, 2014

I can't get Relative paths to work. I have created the class.dat file and I can't get java to recognize it. I am using Eclipse as an IDE. Was wondering if I could get Eclipse to recognize it. I tried with a .txt file as well and couldn't get that to work.

import java.io.*;
public class ReadBytes
{
public static void main(String[] args)
{
try
{
FileInputStream file = new FileInputStream("class.dat");

[Code] .....

View Replies View Related

Swing/AWT/SWT :: How To Download File Using Dynamic Download Path Name Using FileChooser

Apr 11, 2015

I have a FileChooser:

JFrame parentFrame = new JFrame();
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle(txtPushCode.getText());
int userSelection = fileChooser.showSaveDialog(parentFrame);
if (userSelection == JFileChooser.APPROVE_OPTION) {

[Code] ....

But as you can see, it downloads only to "C:android empcoloricon.png". I want to download it to path where I chose in FileChooser with the name and extension I choose. In short, how can I use dynamic file path names in where ever I want in my applications?

View Replies View Related

Batch File With Some Relative Folders

Jul 17, 2014

Batch file (. BAT) problems with some folders on. I created an application in Java and put the JRE folder within the application, because some users do not have Java installed on your machine and the way I did, my application runs. JAR with the JRE that is contained in my application but I created a BAT file that contains the following command:

start "" jre8 bin javaw-jar app.jar

So I run my program in java through the file. BAT calling JRE that is inside the folder and then this JRE runs the mine. JAR and works great anywhere in windows, worked well on a USB key with this command is within. BAT (start "" jre8 bin javaw-jar app.jar).

BAT in certain folders, eg Program Files and Program Files (x86), I need this code to be able to find any directory, regardless of whether the directory has spaces in the name, symbols, numbers or anything else, because maybe people will put the application folder to another location or rename the folder, and if this happens the program will stop working? And especially do not give problems to run inside the Program Files and Program Files (x86) because the application runs everywhere except in these two folders.

View Replies View Related

Swing/AWT/SWT :: How To Scroll Image

Sep 30, 2014

I have a java swing application.

1. The human user of my application asks it to fire up a scanner which scans a paper document. The document is a filled in form.
2. The application then displays the scanned image to the human user.The image is displayed in a JScrollPane since it may be larger than the scroll pane.
3. The human user needs to locate a certain item in the form, for example a social security number, and enter it into a field in a data entry screen.Note that the image and the field appear on the same screen.

Of-course the social security number always appears in the same location in the image. Also the image needs to be the appropriate magnification and resolution to allow the human user to easily read and understand the item he is searching for in the image.

What is the best way to present the scanned image to the user such that he immediately sees the item he requires and can enter it into the data entry field.

View Replies View Related

Swing/AWT/SWT :: JComboBox With Image

Apr 14, 2014

My database contains path of images that I want my jComboBox to diaplay. I have written the following code but it does not work for comboBox but works fine when I display image on jLabel etc. How should I go about this

try {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(updatedetail.class.getName()).log(Level.SEVERE, null, ex);

[Code] ....

View Replies View Related

JPanel Rectangle Drawing Relative To The Full Window

Jun 16, 2014

I'm currently making a Breakout clone to learn about different ways of organizing my code and whatnot but I've run into a problem with the positioning of some pieces versus the position of the mouse.

I've created a blue rectangle on the screen that turns white when the mouse hovers over it, BUT it actually only ends up turning white about halfway down and then continues on off the block. I moved the rectangle to 0,0 to see where it draws and it looks like it is drawing to the very top left corner of the window itself but for the mouse coordinates, the top left is just where the black area is and excludes the borders of the window.

Here is the class rendering the rectangle, it extends from a class that in turn extends from the JPanel class:

public class MainMenuState extends MenuState {
JFrame gameFrame;
Graphics2D g;
// PlayButton variables
int playPosX = 0;
int playPosY = 0;
int playWidth = 100;
int playHeight = 50;

[Code] ....

A few other things I tried that I can think off the top of my head: Play around with different layouts (at times this caused the screen to shrink to a small size as well as using pack()), using setSize() setLocation() or setBorder() in the MainMenuState class which had no effect.

Someone on another forum also suggested trying to utilize component.getLocationOnScreen(): I tried two things with the getXOnScreen method, first subtracting with the location of the JPanel which of course gave me the same problem. After that I tried

MOUSE.x = event.getXOnScreen() - gameFrame.getLocationOnScreen().x;
MOUSE.y = event.getYOnScreen() - gameFrame.getLocationOnScreen().y;

but that resulted in some errors (null pointers) and the mouse was just printing out a position of 0,0

View Replies View Related

JavaFX 2.0 :: SceneBuilder - Preview Classpath-relative Images

May 7, 2014

When I assign a classpath-relative URL to an ImageView's 'Image' property, SceneBuilder is unable to display the Image in the Preview. It shows the text "Image not found" instead as a placeholder, which makes sense. What I'd like to do is add a classpath entry to SceneBuilder such that it is able to locate and display the Images. Any way to accomplish this (or similar)?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved