Images which are shown in netbeans IDE are not shown in real app
I developed an app with a GUI in java with the help of netbeans (I'm using Apache netbeans 9 and JDK 11). Also I have added some images to that Frame. Those images are fine inside netbeans but I cannot see those images in real app which I run through command line.
So this is the way I added images to the app
JButton saveTxtTool = new JButton(new ImageIcon((getClass().getProtectionDomain().getCodeSource().getLocation().toString() + "morsecoder/save-text-large.png").replaceAll("file:/", "")));
Because of this problem I tried this line to get the path that is passed to the ImageIcon.
System.out.println(getClass().getProtectionDomain().getCodeSource().getLocation().toString().replaceAll("file:/","")+"morsecoder/undo.png");
And this is the way I run the app without netbeans with the command prompt.
set Gantt_Generator_v5.0="C:Program Files (x86)GANTT_GENERATOR_V5.0"
start java -cp distMorseCoder.jar morsecoder.MorseCoder
After running the app in both IDE an CMD, these are the results I got.
//in netbeans IDE
C:/Users/Seniru/Documents/MorseCodeConverter/NetBeansProjects/MorseCoder/build/classes/morsecoder/undo.png
//in cmd
C:/Users/Seniru/Documents/MorseCodeConverter/NetBeansProjects/MorseCoder/dist/MorseCoder.jar/morsecoder/undo.png
So I got that the paths are different after these test. So my question is how to solve this problem and what I am doing wrong here.
java image netbeans java-11
|
show 1 more comment
I developed an app with a GUI in java with the help of netbeans (I'm using Apache netbeans 9 and JDK 11). Also I have added some images to that Frame. Those images are fine inside netbeans but I cannot see those images in real app which I run through command line.
So this is the way I added images to the app
JButton saveTxtTool = new JButton(new ImageIcon((getClass().getProtectionDomain().getCodeSource().getLocation().toString() + "morsecoder/save-text-large.png").replaceAll("file:/", "")));
Because of this problem I tried this line to get the path that is passed to the ImageIcon.
System.out.println(getClass().getProtectionDomain().getCodeSource().getLocation().toString().replaceAll("file:/","")+"morsecoder/undo.png");
And this is the way I run the app without netbeans with the command prompt.
set Gantt_Generator_v5.0="C:Program Files (x86)GANTT_GENERATOR_V5.0"
start java -cp distMorseCoder.jar morsecoder.MorseCoder
After running the app in both IDE an CMD, these are the results I got.
//in netbeans IDE
C:/Users/Seniru/Documents/MorseCodeConverter/NetBeansProjects/MorseCoder/build/classes/morsecoder/undo.png
//in cmd
C:/Users/Seniru/Documents/MorseCodeConverter/NetBeansProjects/MorseCoder/dist/MorseCoder.jar/morsecoder/undo.png
So I got that the paths are different after these test. So my question is how to solve this problem and what I am doing wrong here.
java image netbeans java-11
1
you can't just use a path like /.../dist/MorseCoder.jar/morsecoder/undo.png you'll need to research on how to get the resources from within the jar file
– Stultuske
Nov 26 '18 at 10:23
2
You should work with resources - definitely not with files and dependencies on code source.
– RealSkeptic
Nov 26 '18 at 10:24
So how could I get the resources in the java file. I tried, but it didnt work. Are there any API to work with JAR files
– Seniru Pasan
Nov 26 '18 at 11:29
NetBeans 9 does not support the use of JDK 11: NetBeans 9 only implemented "Java 9 and 10 Support". Use a supported JDK and then update your post as appropriate.
– skomisa
Nov 26 '18 at 18:53
@skomisa but I dont think it is a problem with netbeans or jdk - because it can run jdk11 classes too. I think it is a problem with the path
– Seniru Pasan
Nov 27 '18 at 6:17
|
show 1 more comment
I developed an app with a GUI in java with the help of netbeans (I'm using Apache netbeans 9 and JDK 11). Also I have added some images to that Frame. Those images are fine inside netbeans but I cannot see those images in real app which I run through command line.
So this is the way I added images to the app
JButton saveTxtTool = new JButton(new ImageIcon((getClass().getProtectionDomain().getCodeSource().getLocation().toString() + "morsecoder/save-text-large.png").replaceAll("file:/", "")));
Because of this problem I tried this line to get the path that is passed to the ImageIcon.
System.out.println(getClass().getProtectionDomain().getCodeSource().getLocation().toString().replaceAll("file:/","")+"morsecoder/undo.png");
And this is the way I run the app without netbeans with the command prompt.
set Gantt_Generator_v5.0="C:Program Files (x86)GANTT_GENERATOR_V5.0"
start java -cp distMorseCoder.jar morsecoder.MorseCoder
After running the app in both IDE an CMD, these are the results I got.
//in netbeans IDE
C:/Users/Seniru/Documents/MorseCodeConverter/NetBeansProjects/MorseCoder/build/classes/morsecoder/undo.png
//in cmd
C:/Users/Seniru/Documents/MorseCodeConverter/NetBeansProjects/MorseCoder/dist/MorseCoder.jar/morsecoder/undo.png
So I got that the paths are different after these test. So my question is how to solve this problem and what I am doing wrong here.
java image netbeans java-11
I developed an app with a GUI in java with the help of netbeans (I'm using Apache netbeans 9 and JDK 11). Also I have added some images to that Frame. Those images are fine inside netbeans but I cannot see those images in real app which I run through command line.
So this is the way I added images to the app
JButton saveTxtTool = new JButton(new ImageIcon((getClass().getProtectionDomain().getCodeSource().getLocation().toString() + "morsecoder/save-text-large.png").replaceAll("file:/", "")));
Because of this problem I tried this line to get the path that is passed to the ImageIcon.
System.out.println(getClass().getProtectionDomain().getCodeSource().getLocation().toString().replaceAll("file:/","")+"morsecoder/undo.png");
And this is the way I run the app without netbeans with the command prompt.
set Gantt_Generator_v5.0="C:Program Files (x86)GANTT_GENERATOR_V5.0"
start java -cp distMorseCoder.jar morsecoder.MorseCoder
After running the app in both IDE an CMD, these are the results I got.
//in netbeans IDE
C:/Users/Seniru/Documents/MorseCodeConverter/NetBeansProjects/MorseCoder/build/classes/morsecoder/undo.png
//in cmd
C:/Users/Seniru/Documents/MorseCodeConverter/NetBeansProjects/MorseCoder/dist/MorseCoder.jar/morsecoder/undo.png
So I got that the paths are different after these test. So my question is how to solve this problem and what I am doing wrong here.
java image netbeans java-11
java image netbeans java-11
asked Nov 26 '18 at 10:20
Seniru PasanSeniru Pasan
1628
1628
1
you can't just use a path like /.../dist/MorseCoder.jar/morsecoder/undo.png you'll need to research on how to get the resources from within the jar file
– Stultuske
Nov 26 '18 at 10:23
2
You should work with resources - definitely not with files and dependencies on code source.
– RealSkeptic
Nov 26 '18 at 10:24
So how could I get the resources in the java file. I tried, but it didnt work. Are there any API to work with JAR files
– Seniru Pasan
Nov 26 '18 at 11:29
NetBeans 9 does not support the use of JDK 11: NetBeans 9 only implemented "Java 9 and 10 Support". Use a supported JDK and then update your post as appropriate.
– skomisa
Nov 26 '18 at 18:53
@skomisa but I dont think it is a problem with netbeans or jdk - because it can run jdk11 classes too. I think it is a problem with the path
– Seniru Pasan
Nov 27 '18 at 6:17
|
show 1 more comment
1
you can't just use a path like /.../dist/MorseCoder.jar/morsecoder/undo.png you'll need to research on how to get the resources from within the jar file
– Stultuske
Nov 26 '18 at 10:23
2
You should work with resources - definitely not with files and dependencies on code source.
– RealSkeptic
Nov 26 '18 at 10:24
So how could I get the resources in the java file. I tried, but it didnt work. Are there any API to work with JAR files
– Seniru Pasan
Nov 26 '18 at 11:29
NetBeans 9 does not support the use of JDK 11: NetBeans 9 only implemented "Java 9 and 10 Support". Use a supported JDK and then update your post as appropriate.
– skomisa
Nov 26 '18 at 18:53
@skomisa but I dont think it is a problem with netbeans or jdk - because it can run jdk11 classes too. I think it is a problem with the path
– Seniru Pasan
Nov 27 '18 at 6:17
1
1
you can't just use a path like /.../dist/MorseCoder.jar/morsecoder/undo.png you'll need to research on how to get the resources from within the jar file
– Stultuske
Nov 26 '18 at 10:23
you can't just use a path like /.../dist/MorseCoder.jar/morsecoder/undo.png you'll need to research on how to get the resources from within the jar file
– Stultuske
Nov 26 '18 at 10:23
2
2
You should work with resources - definitely not with files and dependencies on code source.
– RealSkeptic
Nov 26 '18 at 10:24
You should work with resources - definitely not with files and dependencies on code source.
– RealSkeptic
Nov 26 '18 at 10:24
So how could I get the resources in the java file. I tried, but it didnt work. Are there any API to work with JAR files
– Seniru Pasan
Nov 26 '18 at 11:29
So how could I get the resources in the java file. I tried, but it didnt work. Are there any API to work with JAR files
– Seniru Pasan
Nov 26 '18 at 11:29
NetBeans 9 does not support the use of JDK 11: NetBeans 9 only implemented "Java 9 and 10 Support". Use a supported JDK and then update your post as appropriate.
– skomisa
Nov 26 '18 at 18:53
NetBeans 9 does not support the use of JDK 11: NetBeans 9 only implemented "Java 9 and 10 Support". Use a supported JDK and then update your post as appropriate.
– skomisa
Nov 26 '18 at 18:53
@skomisa but I dont think it is a problem with netbeans or jdk - because it can run jdk11 classes too. I think it is a problem with the path
– Seniru Pasan
Nov 27 '18 at 6:17
@skomisa but I dont think it is a problem with netbeans or jdk - because it can run jdk11 classes too. I think it is a problem with the path
– Seniru Pasan
Nov 27 '18 at 6:17
|
show 1 more comment
0
active
oldest
votes
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479005%2fimages-which-are-shown-in-netbeans-ide-are-not-shown-in-real-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479005%2fimages-which-are-shown-in-netbeans-ide-are-not-shown-in-real-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
you can't just use a path like /.../dist/MorseCoder.jar/morsecoder/undo.png you'll need to research on how to get the resources from within the jar file
– Stultuske
Nov 26 '18 at 10:23
2
You should work with resources - definitely not with files and dependencies on code source.
– RealSkeptic
Nov 26 '18 at 10:24
So how could I get the resources in the java file. I tried, but it didnt work. Are there any API to work with JAR files
– Seniru Pasan
Nov 26 '18 at 11:29
NetBeans 9 does not support the use of JDK 11: NetBeans 9 only implemented "Java 9 and 10 Support". Use a supported JDK and then update your post as appropriate.
– skomisa
Nov 26 '18 at 18:53
@skomisa but I dont think it is a problem with netbeans or jdk - because it can run jdk11 classes too. I think it is a problem with the path
– Seniru Pasan
Nov 27 '18 at 6:17