有人能告诉我如何在获得jTextFields
的值后更改a1、a2、a3、a4、a5的字体吗?这样,如果我在JOptionPane
上显示它,每个变量的赋值都有颜色
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String a1 = jTextField1.getText();
String a2 = jTextField2.getText();
String a3 = jTextField3.getText();
String a4 = jTextField4.getText();
String a5 = jTextField5.getText();
String m1 = "You will never forget " + a1 + "nn";
String m2 = "You can consider " + a2 + " as your true friend nn";
String m3 = "You really Love " + a3 + "nn";
String m4 = a4 + " is your twin soul nn" ;
String m5 = "you will remember " + a5 + " for the rest of your life (due to past –good or bad- experiences, lessons etc) nn";
String m6 = m1 + m2 + m3 + m4 + m5;
JOptionPane.showMessageDialog(null,m6);
}
请参阅如何在Swing组件中使用HTML。示例:
String m1 = "<html>You will never forget <b>" + a1 + "</b></html>";
现在a1
将出现在粗体中。
您应该创建Label,设置Font,然后使用它来创建messageDialog。试试这样的东西:
String a1 = jTextField1.getText();
String a2 = jTextField2.getText();
String a3 = jTextField3.getText();
String a4 = jTextField4.getText();
String a5 = jTextField5.getText();
String m1 = "You will never forget " + a1 + "nn";
String m2 = "You can consider " + a2 + " as your true friend nn";
String m3 = "You really Love " + a3 + "nn";
String m4 = a4 + " is your twin soul nn" ;
String m5 = "you will remember " + a5 + " for the rest of your life (due to past –good or bad- experiences, lessons etc) nn";
String m6 = m1 + m2 + m3 + m4 + m5;
JLabel label = new JLabel(m6);
label.setFont(new Font("serif", Font.BOLD, 14));
JOptionPane.showMessageDialog(null,label);