【发布时间】:2015-10-09 03:35:46
【问题描述】:
我有一个与 GUI 相关的问题。我正在尝试使用 JOptionsPane 以及 JPanel、JText 和 JLabel 创建一个 GUI。现在我已经完成了 GUI 的构建并让标签工作,我的下一个目标是围绕我的 GUI 的格式化文本创建一个表格,我将在下面发布我的代码来说明:
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";
昨天有人让我开始使用可行的 CSS,但现在我需要弄清楚如何在整个事物周围放置某种类型的表格,以便我可以组织这个文本密集的对话框。从我的变量中可以看出,我尝试使用像 <span style='border:1px dottec red'> 这样的 CSS 标记,但这没有效果。
当我在 CSS 之外添加标准 HTML 表格标记时,它可以工作,但是我的 CSS 不再工作(如您测试程序时所见)。移除表格边框将再次允许 CSS 工作。
如何让span style='border' 工作,或者如何让表格边框与 CSS 一起工作?
编辑:
这里是根据要求额外的可运行代码。
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);
}
}
你会发现给我带来麻烦的是:
String header1Css = "<span style = 'font-size:15; font-weight:bold;text-decoration:underline;border:1px dotted red'>";
我已将该线设置为具有 1 px 的红色虚线边框。该格式字符串在这里被调用:
"<br><br><br>"+header1Css+"Entry Detail:"+endSpanCss +
结果是“条目详细信息:”行的格式正确,除了边框之外的所有内容。
【问题讨论】:
-
请格式化您的代码,难以阅读。此外,您似乎只发布了定义几个字符串的部分 - 添加更多代码以查看您实际使用它们的方式可能会有很大帮助。
-
代码将近 3700 行。我发布的字符串仅与 JOptionsPane 相关,这与其余代码真正分开。我定义的所有字符串都在我发布的代码中使用,主要在这一行:" + table + css + batchCss + "1 of 2" +endSpanCss+ endSpanCss + endTable + "
-
知道了,但是您如何实际使用这些字符串?除此之外,您可能应该使用
"而不是',例如<span style="border:1px dotted red"> -
我使用字符串来保存 的值。我这样做是因为稍后我可能会将字符串移到方法之外,以便我可以重用它们。所以基本上每个字符串都会包含各种格式属性,然后我将它们插入到我的 GUI 的文本中,就像我上面的 JLabel 一样。主要问题是 根本不起作用,而常规 HTML 边框标签起作用,它使所有其他 属性无效。我很乐意分享我的代码,但你不会对这个组织感到满意。
-
感谢代码更新,但我有个坏消息 - 经过一番挖掘后,看起来您尝试实现的目标目前无法实现,因为“边框”和其他几个属性当前未用于渲染。见相关JavaDoc