Ok, I am very, very new to Java and am self taught, so no making fun of my bad coding ;)
I am messing around with Java fx and am trying to insert an image into a borderpane layout.
this is the method that is in the controller I am using to make an image appear but I cant get the filepath to work. It currently has "/images/brownBear.jpg" as the filepath, but I've tried the relative path-
com/jaimependlebury/mammal/images/brownBear.jpg
and the full path and everything in between and i either get a
FileNotFoundException
or
NullPointerErrorException
I'm not even sure I set it up correctly, I've found different things on different websites and have tried to piece information together, so any help would be appreciated.
FXML file
<ImageView fx:id="picture">
</ImageView>
Controller file-
I have the ImageView picture variable declared at the top of the class, I just didn't include it in the code block.
#FXML
public void handleMammalListView()throws FileNotFoundException {
Species species= mammalList.getSelectionModel().getSelectedItem();
picture=new ImageView();
Image img =new Image(new FileInputStream("/images/brownBear.jpg"));
picture.setImage(img);
speciesName.setText(species.getSpeciesName());
details.setText(
"Scientific name: " + species.getScientificName() +"\n"+
"Staus: " + species.getStatus() + "\n" +
"Distribution: " + species.getHabitat() +"\n" +
"Food: " + species.getFood() + "\n" +
"Birth: " + species.getBirth() + "\n" +
"Distinguishing Characteristics: " + species.getBodyType() + "\n"+
"Nursing: " + species.getNurse() + "\n" +
"Type of hair: " + species.getTypeOfHair());
The following line of code:
picture=new ImageView();
Is resetting the reference you set in your FXML - you can just remove it.
Related
I wanted to loop through a folder containig .mp3 files and changing their album names (if they don't have one) to their title (e.g. Remix.mp3 with Title "Remix" gets the Album "Remix") using mp3agic.
This is my code so far:
if (mp3file.hasId3v1Tag()) {
ID3v1 id3v1Tag = mp3file.getId3v1Tag();
try {
if (id3v1Tag.getAlbum().equals("")) {
id3v1Tag.setAlbum(id3v1Tag.getTitle());
mp3file.save(SAVE_DIR + "\\" + child.getName());
System.out.println(SAVE_DIR + "/" + child.getName());
} else {
mp3file.save(SAVE_DIR + "/" + child.getName());
}
} catch (Exception e) {
mp3file.save(SAVE_DIR + "/" + child.getName());
}
}
I get the following error:
Exception in thread "main" com.mpatric.mp3agic.NotSupportedException: Packing Obselete frames is not supported
at com.mpatric.mp3agic.ID3v2ObseleteFrame.packFrame(ID3v2ObseleteFrame.java:32)
at com.mpatric.mp3agic.ID3v2Frame.toBytes(ID3v2Frame.java:83)
at com.mpatric.mp3agic.AbstractID3v2Tag.packSpecifiedFrames(AbstractID3v2Tag.java:275)
at com.mpatric.mp3agic.AbstractID3v2Tag.packFrames(AbstractID3v2Tag.java:261)
at com.mpatric.mp3agic.AbstractID3v2Tag.packTag(AbstractID3v2Tag.java:227)
at com.mpatric.mp3agic.AbstractID3v2Tag.toBytes(AbstractID3v2Tag.java:218)
at com.mpatric.mp3agic.Mp3File.save(Mp3File.java:450)
at de.thejetstream.main.Iterator.(Iterator.java:57)
at de.thejetstream.main.Main.main(Main.java:12)
at this file:
name: Feel Good in Black and Yellow.mp3
title: Feel Good in Black and Yellow (feat. Gorillaz & De La Soul)
album: Black and Yellow - Single
It crashes at line 57, which equals to the last save (in the catch).
What is the problem with this code? Is it just because the file uses an old kind of codec or something like this?
I found the solution:
The problem was that these files used ip3v2 tags instead of ip3v1. Simply checking which on it is and adjusting the code accordingly solved everything.
I have a GUI related question. I am attempting to use create a GUI using a JOptionsPane as well as JPanel, JText and JLabel. Now that I have accomplished building my GUI and getting the tag to work my next goal is to create a table around the formatted text of my GUI, I will post my code below to illustrate:
String css = "<span style='font-size:10; color: white; background-color:black'>";
String batchCss = "<span style='font-size: 20'>";
String cssBorder = "<span style='border:1px dotted red'>";
String endSpanCss = "</span>"; String table = "
<table border=4>"; String endTable = "</table>"; String text = "
<html>" + table + css + batchCss + "1 of 2" +endSpanCss+ endSpanCss + endTable + "
<br>Entry Detail:" + "
<br>11111111111111111111111111+ "
<br>
<br>Please type 1-21 to apply a reason code and addenda record to the entry detail." + "
<br>Please type 'h' and press any button to open the help screen." + "
<br>
<br>
<br>Reason Codes" + "
<br>R01 - Insufficient Funds" + "
<br>R02 - Account Closed" + "
<br>R03 - No Account" + "
<br>R04 - Invalid Account Number" + "
<br>R05 - Unauthorized Debit to Consumer Account" + "
<br>R06 - Returned per ODFI Request" + "
<br>R07 - Auth Revoked by Customer" + "
<br>R08 - Payment Stopped" + "
<br>R09 - Uncollected Funds" + "
<br>R10 - Customer Advises Not Authorized" + "
<br>R11 - Check Truncation Entry Return" + "
<br>R12 - Branch Sold to Another DFI" + "
<br>R13 - Invalid ACH Routing Number" + "
<br>R14 - Represenative Payee Deceased or Unable to Continue" + "
<br>R15 - Beneficiary or Account Holder Deceased" + "
<br>R16 - Account Frozen" + "
<br>R17 - File Record Edit Criteria" + "
<br>R18 - Improper Effective Entry Date" + "
<br>R19 - Account Field Error" + "
<br>R20 - Non-Transaction Amount" + "
<br>R21 - Invalid Company Information" + "
<br>R22 - Invalid Individual ID Number";
Someone yesterday got me started with the CSS which works, but now I need to figure out how to put some type of table around the whole thing so I can organize this text-heavy dialog. I have tried to use a CSS tag like <span style='border:1px dottec red'> as you can see from my variables, but this had no effect.
When I add the standard HTML table tag outside the CSS it works however my CSS no longer works (as you can see if you test the program). Removing the table border will again allow the CSS to work.
How can I get the span style='border' to work, or how can I get the table border to work with the CSS?
EDITED:
Here is additionally runnable code as requested.
package nacha;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Testing4
{
public static void main(String args[]){
String css = "<span style='font-size:10; color: white; background-color:black'; border:>";
String batchCss = "<span style='font-size: 20'>";
String endSpanCss = "</span>";
String table = "<table border=4>";
String endTable = "</table>";
String mainCss = "<span style='font-size:12; color: red'>";
String header1Css = "<span style = 'font-size:15; font-weight:bold;text-decoration:underline;border:1px dotted red'>";
String text1Css = "<span style = 'font-size:12; font-style:italic'>";
String text = "<html>" +
css + batchCss + "1 of 2"+endSpanCss+endSpanCss+ endSpanCss +
"<br><br><br>"+header1Css+"Entry Detail:"+endSpanCss +
"<br>"+mainCss+"111111111111111111111"+endSpanCss+
"<br><br><br>"+text1Css+"Please type 1-21 to apply a reason code and addenda record to the entry detail." +
"<br>Please type 'h' and press the next entry button to open the help screen."+endSpanCss +
"<br><br><br>"+header1Css+"Reason Codes"+ endSpanCss +
"<br>"+table+"R01 - Insufficient Funds" +
"<br>R02 - Account Closed" +
"<br>R03 - No Account" +
"<br>R04 - Invalid Account Number" +
"<br>R05 - Unauthorized Debit to Consumer Account" +
"<br>R06 - Returned per ODFI Request" +
"<br>R07 - Auth Revoked by Customer" +
"<br>R08 - Payment Stopped" +
"<br>R09 - Uncollected Funds" +
"<br>R10 - Customer Advises Not Authorized" +
"<br>R11 - Check Truncation Entry Return" +
"<br>R12 - Branch Sold to Another DFI" +
"<br>R13 - Invalid ACH Routing Number" +
"<br>R14 - Represenative Payee Deceased or Unable to Continue" +
"<br>R15 - Beneficiary or Account Holder Deceased" +
"<br>R16 - Account Frozen" +
"<br>R17 - File Record Edit Criteria" +
"<br>R18 - Improper Effective Entry Date" +
"<br>R19 - Account Field Error" +
"<br>R20 - Non-Transaction Amount" +
"<br>R21 - Invalid Company Information" +
"<br>R22 - Invalid Individual ID Number"+endTable;
//Below code creates the GUI for the return builder portion of the program.
Object[] options1 = {"Next Entry","Next Batch","Finished"};//Changes the default buttons.
BorderLayout border = new BorderLayout();
JPanel panel = new JPanel();
panel.setLayout(border);
panel.add(new JLabel(text),BorderLayout.NORTH);//Adds the label to the top of the panel.
JTextField textField = new JTextField(10);
panel.add(textField,BorderLayout.SOUTH);//Adds a user-input text area to the bottom of the panel.
int result = JOptionPane.showOptionDialog(null, panel, "Return Builder", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options1, JOptionPane.YES_OPTION);
}
}
You will find the line giving me trouble is:
String header1Css = "<span style = 'font-size:15; font-weight:bold;text-decoration:underline;border:1px dotted red'>";
I have set that line to have a 1 px dotted red border. That format string is called here:
"<br><br><br>"+header1Css+"Entry Detail:"+endSpanCss +
And the result is the "Entry Detail:" line is formatted correctly for everything except the border.
Solved.
What I was trying to accomplish is not currently possible as the border is not used for rendering.
Source:
http://docs.oracle.com/javase/8/docs/api/javax/swing/text/html/CSS.html
Thanks Sva.MU for assisting with this.
Using ZK, I'm trying to add a script into the header tag programmatically.
How can I do this?
Finally I found a solution! Someone in ZK's Forum gives these possible solutions:
http://forum.zkoss.org/question/96845/using-zk-5-how-to-add-a-script-into-the-head-tag-from-java/
"I know two ways for that:
1.Put the declarartion of the javascript file in the lang-addon.xml
lang-addon.xml
<?xml version="1.0" encoding="UTF-8"?>
<language-addon>
. . .
<!-- 4. Path to Bootstrap javascript library -->
<javascript src="~./cyborg/less/bootstrap/js/bootstrap.min.js" type="text/javascript" charset="UTF-8" />
</language-addon>
2. Add manual in java code:
if (view instanceof Window) {
Window win = (Window) view;
PageCtrl pc = (PageCtrl) win.getPage();
pc.addBeforeHeadTags("<script type=\"text/javascript\">" + "(function(i,s,o,g,r,a,m)"
+ "{i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){"
+ "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();" + "a=s.createElement(o),"
+ "m=s.getElementsByTagName(o)[0];" + "a.async=1;a.src=g;m.parentNode.insertBefore(a,m)" + "})"
+ "(window,document,'script','//www.google-analytics.com/analytics.js','ga');" + "ga('create', "
+ this.trackingID + ", 'auto'); " + "ga('send', 'pageview');" + "</script>");
} else {
throw new UiException("This view model must be applied from a Window component.");
}
from api:
void org.zkoss.zk.ui.sys.PageCtrl.addBeforeHeadTags(String tags)
Adds the tags that will be generated inside the head element and before ZK's default tags. For example,
((PageCtrl)page).addBeforeHeadTags("");
"
I have a tool what uses Perforce. When it merge a branch back to the parent, mark the project branch with checkout a text file, and submit it unchanged. This tool also use that text file, for read the actual build number. My problem is, a "/n" appeared in the text, and because it have to contain just numbers, it's a big problem.
Have anyone met this problem, or this can't caused by P4C?
Maybe important, I don't use P4JAVA here.
Please note that I'm debugging right now, and I'm not sure the problem is here, but at the moment this seems the most probable.
//<path> is a legit path, I just shortened the code here
commandSync = "p4 -d " + getPerforceRoot() + " sync " + selectedDataBean.getP4Path() + "<path>/BuildNum.txt";
CommandResultBean syncCommandResult = commandExecuter.runAndGetResults(commandSync);
//command executer that runs the command string in cmd
commandMark = "p4 -d " + getPerforceRoot() + " edit -c " + changelistNumber + " " + selectedDataBean.getP4Path() + "<path>/BuildNum.txt";
CommandResultBean markCommandResult = commandExecuter.runAndGetResults(commandMark);
commandSubmit = "p4 -d " + getPerforceRoot() + " submit -f submitunchanged -c " + changelistNumber;
CommandResultBean submitCommandResult = commandExecuter.runAndGetResults(commandSubmit);
I got my inv finally working! :D But, you know... now... it's dumb. I want it to say "Use Item 1" or whatever when I Right-click so I do this:
if (actItemx == "Item 1") {
popup.add(dropMenuItem + " " + actItemx); // should print "Use Item 1"
popup.add(cancelMenuItem);
}
Looks fine to me... but... when I compile, it's fine. When I run it, it's fine... but when I DO IT:
I would have sworn that because it's displayed correctly in CMD that it would display correctly on JMenu... weird.
popup.add(dropMenuItem + " " + actItemx);
That command is adding the toString() representaion of the dropMenuItem Swing component, plus a space, the the String value of actItemx.
I would guess you want:
popup.add(dropMenuItem.getText() + " " + actItemx);