X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FJvSwingUtils.java;h=b25b2c884d447f13c1e39c1d6baf013657a42aaf;hb=c0a37536d35fb247404187b367228e71f85ce373;hp=ef96fa6144720c6dd0170a7ca1251ea67029940a;hpb=14307f5cfcbc90c419c892434613a500ca550ecc;p=jalview.git diff --git a/src/jalview/gui/JvSwingUtils.java b/src/jalview/gui/JvSwingUtils.java index ef96fa6..b25b2c8 100644 --- a/src/jalview/gui/JvSwingUtils.java +++ b/src/jalview/gui/JvSwingUtils.java @@ -35,6 +35,7 @@ import java.util.List; import java.util.Objects; import javax.swing.AbstractButton; +import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JComponent; @@ -44,6 +45,8 @@ import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JScrollBar; import javax.swing.SwingConstants; +import javax.swing.border.Border; +import javax.swing.border.TitledBorder; /** * useful functions for building Swing GUIs @@ -53,12 +56,15 @@ import javax.swing.SwingConstants; */ public final class JvSwingUtils { + public static final String HTML_PREFIX = "
"; + /** * wrap a bare html safe string to around 60 characters per line using a CSS * style class specifying word-wrap and break-word * * @param enclose - * if true, add <html> wrapper tags + * if true, add <html> wrapper tags (currently false for only + * two references -- both in Jws2Discoverer -- * @param ttext * * @return @@ -91,10 +97,12 @@ public final class JvSwingUtils { return enclose ? "" + ttext + "" : ttext; } - - return (enclose ? "" : "") - + "

" - + ttext + "

" + ((enclose ? "" : "")); + // BH 2018,2019 + return (enclose + ? HTML_PREFIX + + ttext + + "
" + : ttext); } @@ -351,4 +359,29 @@ public final class JvSwingUtils return combo; } + /** + * Adds a titled border to the component in the default font and position (top + * left), optionally witht italic text + * + * @param comp + * @param title + * @param italic + */ + public static TitledBorder createTitledBorder(JComponent comp, + String title, boolean italic) + { + Font font = comp.getFont(); + if (italic) + { + font = new Font(font.getName(), Font.ITALIC, font.getSize()); + } + Border border = BorderFactory.createTitledBorder(""); + TitledBorder titledBorder = BorderFactory.createTitledBorder(border, + title, TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, + font); + comp.setBorder(titledBorder); + + return titledBorder; + } + }