Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. jLabel.setFont(new Font("Tahoma",1,20));
  2.  
  3. JLabel label = new JLabel("some text - WE ARE UNDERLINED");
  4. MouseListener l = new MouseAdapter() {
  5. Font original;
  6.  
  7. @Override
  8. public void mouseEntered(MouseEvent e) {
  9. original = e.getComponent().getFont();
  10. Map attributes = original.getAttributes();
  11. attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
  12. e.getComponent().setFont(original.deriveFont(attributes));
  13. }
  14.  
  15. @Override
  16. public void mouseExited(MouseEvent e) {
  17. e.getComponent().setFont(original);
  18. }
  19.  
  20.  
  21. };
  22. label.addMouseListener(l);
  23. JComponent content = new JPanel();
  24. content.add(label);
  25. content.add(new JButton("dummy focus"));
  26.  
  27. JLabel#setFont(new Font(attributes));
  28.  
  29. JLabel#setFont(new Font("Serif", Font.BOLD, 16));
  30.  
  31. final Map attributes = (new Font("Serif", Font.BOLD, 16)).getAttributes();
  32. attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
  33.  
  34. yourLabel.setText(htmlIfy("<p style='color:#1C66AE;'>Your text here</p>"));
  35.  
  36. private static final String HTML = "<html>";
  37. private static final String HTML_END = "</html>";
  38.  
  39.  
  40. public static String htmlIfy(String s) {
  41. return HTML.concat(s).concat(HTML_END);
  42. }
  43.  
  44. yourLabel.setText(HTMLTagUtil.htmlIfy(HTMLTagUtil
  45. .linkIfy("Your Text Here")));//Forgot Password?
  46.  
  47. yourLabel.setCursor(new java.awt.Cursor(
  48. java.awt.Cursor.HAND_CURSOR));
  49.  
  50. private static final String A_HREF = "<a href="";
  51. private static final String HREF_CLOSED = "">";
  52. private static final String HREF_END = "</a>";
  53. public static String linkIfy(String s) {
  54. return A_HREF.concat(s).concat(HREF_CLOSED).concat(s).concat(HREF_END);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement