JComponents inside JOptionPane.showMessageDialog();


/ Published in: Java
Save to your folder(s)

I didnt know you could do this but you can put JComponets from awt or swing inside
JOptionPane.showMessageDialog ...probly other variations also who knows

this is excellent for html formatting inside a messagebox


Copy this code and paste it in your HTML
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4. String test = "<html><font color=green>Test<br></font></html>";
  5. ShowMsg(test,"Testing HTML");
  6.  
  7.  
  8. public static void ShowMsg(String in,String title)
  9. {
  10. JOptionPane.showMessageDialog( null,
  11. new JLabel(in),title,JOptionPane.INFORMATION_MESSAGE );
  12. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.