Putting a table-border around a <span> in Java Swing - java
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.
Related
Spring REST Docs - fieldWithPath in Junit Test
I have a Spring Boot v1.5.14.RELEASE app., Using Spring Initializer, JPA, embedded Tomcat and following the RESTful API architecture principes. I have created this test #Test public void createCustomerChain() throws Exception { this.mockMvc.perform(post("/customer/createCustomer") .contentType(MediaType.APPLICATION_JSON_VALUE) .content("{\n" + " \"subSegment\":\"25\",\n" + " \"legalLanguage\":\"NL\",\n" + " \"isRestrictel\":true,\n" + " \"isCommunicationLanguageForAllAccount\":true,\n" + " \"isAntiMarketing\":true,\n" + " \"hotelChain\":{\n" + " \"legalForm\":\"09\",\n" + " \"foundationDate\":\"2001-12-17T09:30:47Z\",\n" + " \"tradingName\":\"COMPANY NAME\",\n" + " \"printName\":\"TEST PRINT\",\n" + " \"naceCode\":\"16230\",\n" + " \"vatNumber\":\"41223334343\", \n" + " \"countryVatCode\":\"IN\",\n" + " \"isSubjectToVAT\":true,\n" + " \"sectorCode\":\"85\",\n" + " \"legalAddress\": {\n" + " \"mainkey\":2088512,\n" + " \"subkey\":3256\n" + " }\n" + " },\n" + " \"isVATNumberOnBill\":true,\n" + " \"communicationLanguage\":\"EN\"\n" + "}")) .andExpect(status().isOk()) .andDo(document("customer-create-request-Chain", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), responseFields( fieldWithPath("billingAccountId").description("The billing account id of the newly created customer"), fieldWithPath("paymentAgreementId").description("The Payment Agreement Id of the newly created customer"), fieldWithPath("customerId").description("The id of the new created customer"), fieldWithPath("isNewlyCreated").description("Set to `true` when the customer is newly created")), requestFields( fieldWithPath("subSegment").description("Market subsegment"), fieldWithPath("legalLanguage").description("Legal language"), fieldWithPath("isAntiMarketing").description("If true, customer does not want to have any marketing contact"), fieldWithPath("isRestrictel").description("Indicates that the customer is on the orange list. Do not disclose information to other companies for commercial purposes."), fieldWithPath("hotelChain.legalAddress.mainkey").description("LAM mainkey of the address. If the mainkey and the subkey is given the rest of the address information is not needed."), fieldWithPath("hotelChain.legalAddress.subkey").description("LAM subkey of the address"), fieldWithPath("hotelChain.legalForm").description("Legal form"), fieldWithPath("hotelChain.foundationDate").description("Date of the foundation of a company(mandatory field for 'Chain' customer type)"), fieldWithPath("hotelChain.vatNumber").description("Enterprise or VAT number"), fieldWithPath("hotelChain.countryVatCode").description("ISO2 country code of the VAT number"), fieldWithPath("isVATNumberOnBill").description("Indicates if the VAT number will be shown on the bill"), fieldWithPath("hotelChain.isSubjectToVAT").description("Indicates if the enterprise number is a real VAT or not"), fieldWithPath("hotelChain.sectorCode").description("Subtitle Description. Additional information relating to the customer. Name-Value pairs"), fieldWithPath("hotelChain.tradingName").description("Trading name"), fieldWithPath("hotelChain.printName").description("Print name of the customer"), fieldWithPath("hotelChain.naceCode").description("Nace code"), fieldWithPath("communicationLanguage").description("Communication language"), fieldWithPath("isCommunicationLanguageForAllAccount") .description("If true, commercial language of all BGC billing accounts receive the value defined at customer level and users not allowed to change commercial language of any billing account")))); } and this is the result of running the test: org.springframework.restdocs.snippet.SnippetException: Fields with the following paths were not found in the payload: [customerId] and removing the customerId from fieldWithPath test passed successfully but, I wonder why I don't have the same error for such a field like billingAccountId
This is due to customerId field could be null or absent in some cases. You can use optional for it: fieldWithPath("customerId").description("Description").optional() To find a more precise reason, please, post the code of the createCustomer() method.
Button defaults to being disabled even though I enabled it
Button keeps being disabled even though a specified it to be enabled I've tried placing the enabling code in different areas, but nothing has worked. btn_Receipt.setEnabled(true); btn_Reset.setEnabled(true); txtA_ProofOfPurchase.setEnabled(true); double deposit = Double.parseDouble(JOptionPane.showInputDialog("Please specify the amount of money that you would like to withdraw (in Rands)")); String name = "Nia Sanderson"; String action ="Deposit"; txtA_ProofOfPurchase.setText ("******************************* \nNedbank Online Banking " + "\nCustomers Name: " + name + "\nAction: " + action + "\nDeposit Amount: R " + deposit + "\n*******************************" ); I expect the output to result in the two buttons and text area being enabled
JavaFX inserting an image
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.
giving each file a proper html5 tag based on MIME type to be displayed in an html+bootstrap template
I created a web server in java that basically list all the files on a device. I want to create a cool, responsive UI using bootstrap to display those files on the client's browser; however, I know that just creating an link to each file won't get me anywhere. Here is some code before I continue: for (File f : files.toArray(new File[files.size()])) { filesAsLinks += "<a href=\"/Files" + f.toURI().getPath().replace(":", "") + "\">" + f.getPath() + "</a>" + "<br>"; } I am thinking to create a Handler that is responsible for giving the file that it receives a proper html5 tag. For example: Handler.handle (String path) { Path source = new Path(source); String contentType = Files.probeContentType(source); // last two lines to get the content type of a file if (contentType.startsWith("video")) { return "video width=\"320\" height=\"240\" controls> " + "<source src=\"pathRelated/video.mp\" ;type=" + contentType + " >"; } } Would that be the relatively right thing to do before even thinking about making a template with bootstrap, or should I make the template first? So far I have been replacing the generated links String with a simple html template that contains some placeholders like "ContentGoesHere" in the following template: "<html xmlns=\"http://www.w3.org/1999/xhtml\"> "+ "<head>"+ " <title>Max Server</title>"+ "</head>"+ "<body style=\"width: 100%; height:100%;\">"+ " <table width=\"100%\">"+ " <tr>"+ " <td colspan=\"2\" style=\"background-color: #FFA500;height:10px\">"+ " <h1> HTTP Server</h1>"+ " </td>"+ "<td colspan=\"1\" style=\"background-color: #FFA500;height:10px;white-space: nowrap;\"></td>"+ " </tr>"+ " <tr>"+ " <td style=\"background-color: #FFD700; width: 100px;\" valign=\"top\">"+ " <b>Menu</b><br />"+ " Files<br />"+ " Messages<br />"+ " Contacts<br />"+ " Settings<br />"+ " Info"+ " </td>"+ " <td style=\"float: left; margin: 5px;width:100%\" align=\"left\" valign=\"top\">"+ " ContentGoesHere"+ " </td>"+ " </tr>"+ " <tr>"+ " <td colspan=\"2\" style=\"background-color:#FFA500;clear:both;text-align:center;height:20px;\">"+ " " </td>"+ " </tr>"+ " </table>"+ "</body>"+ "</html>"; The final result string (template+content) is written to the client's socket output stream and sent to the client.
I know that just creating an link to each file wont get me anywhere Simply creating a link would work - it would open the video and the browser would handle the actual viewing of the file based off the mime-type of the file you are accessing. If, on the other hand, you want to display each item on the same page so you have a nice format and the files being shown (think YouTube or another site), then creating the html for the different elements would be correct. I would advise creating the html based off the file extension rather than off the mime-type. To your "which first" question, that is up to you. You can start with the template or the content within the template, depending on your work flow and what you are most comfortable with.
P4 edit can cause whitespace without edit?
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);