Java 在Swing中使用HTML代码
我不知道如何在HTML中使用变量,在这种情况下字符串是一个变量Java 在Swing中使用HTML代码,java,html,swing,joptionpane,Java,Html,Swing,Joptionpane,我不知道如何在HTML中使用变量,在这种情况下字符串是一个变量 JOptionPane.showMessageDialog(null,"<html>Error #1<br> + string +</html>","Error",JOptionPane.PLAIN_MESSAGE); JOptionPane.showMessageDialog(空,“错误1+string+”,“错误”,JOptionPane.PLAIN\u消息); 此输出:错误#1+字符串
JOptionPane.showMessageDialog(null,"<html>Error #1<br> + string +</html>","Error",JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(空,“错误1
+string+”,“错误”,JOptionPane.PLAIN\u消息);
此输出:错误#1+字符串
JOptionPane.showMessageDialog(null,"<html>Error #1<br></html>" + string ,"Error",JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(空,“错误1
”+字符串,“错误”,JOptionPane.PLAIN\u消息);
此输出:错误#1
有没有一种方法可以在HTML中使用字符串变量?是否需要类似的内容
"<html>Error #1<br>" + string + "</html>"
“错误1”
“+string+”
??
如果要将
字符串
变量连接到html,它必须在引号之外,否则它将被视为文本,如您的示例所示。是否需要类似的内容
"<html>Error #1<br>" + string + "</html>"
JOptionPane.showMessageDialog(
null,
"<html>Error #1<br>" + string + "</html>",
"Error",
JOptionPane.PLAIN_MESSAGE);
“错误1”
“+string+”
??
如果要将字符串
变量连接到html,它必须在引号之外,否则将被视为文本,如您的示例所示。JOptionPane.showMessageDialog(
JOptionPane.showMessageDialog(
null,
"<html>Error #1<br>" + string + "</html>",
"Error",
JOptionPane.PLAIN_MESSAGE);
无效的
“错误#1
”+字符串+“”,
“错误”,
JOptionPane.普通消息);
尽管如此,请注意逻辑上的JOptionPane.PLAIN\u消息应为JOptionPane.ERROR\u消息
JOptionPane.showMessageDialog(
无效的
“错误#1
”+字符串+“”,
“错误”,
JOptionPane.普通消息);
但是请注意,逻辑上JOptionPane.PLAIN\u MESSAGE
应该是JOptionPane.ERROR\u MESSAGE
,您需要执行以下操作:“ERROR”1
“+string+”
java中的字符串文字由零个或多个字符组成,这些字符用双引号括起来。所以任何满足这个条件的东西也将被视为字符串。在追加字符串之前,需要先关闭该字符串
因此,如果string=“Hi to stack”
:
然后,“Error”1
“+string+”
将导致:
"<html>Error #1<br>Hi to stack</html>"
“错误#1
堆栈高”
您需要执行:错误1
“+string+”
java中的字符串文字由零个或多个字符组成,这些字符用双引号括起来。所以任何满足这个条件的东西也将被视为字符串。在追加字符串之前,需要先关闭该字符串
因此,如果string=“Hi to stack”
:
然后,“Error”1
“+string+”
将导致:
"<html>Error #1<br>Hi to stack</html>"
“错误#1
堆栈高”
JOptionPane.showMessageDialog(null,“Error#1
“+string+”,“Error”,JOptionPane.showMessageDialog(null,“Error#1
“+string+”,“Error”,