Swing/ClippedHtmlLabel のバックアップ差分(No.4)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/ClippedHtmlLabel へ行く。
- 1 (2009-07-06 (月) 15:24:09)
- 2 (2010-05-07 (金) 13:50:43)
- 3 (2013-01-08 (火) 18:36:35)
- 4 (2013-10-17 (木) 14:59:05)
- 5 (2014-12-06 (土) 20:45:52)
- 6 (2015-01-25 (日) 18:34:34)
- 7 (2016-08-10 (水) 20:54:23)
- 8 (2017-09-28 (木) 15:06:15)
- 9 (2017-11-08 (水) 18:05:14)
- 10 (2017-11-08 (水) 19:59:19)
- 11 (2019-05-22 (水) 19:35:38)
- 12 (2019-06-27 (木) 16:39:54)
- 13 (2021-03-07 (日) 18:26:16)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:Htmlで修飾した文字列のクリップ #navi(../) #tags() #tags(Html, JTable, TableCellRenderer, JLabel) RIGHT:Posted by &author(aterai); at 2009-07-06 *Htmlで修飾した文字列のクリップ [#j2842464] Htmlで文字列を修飾するとクリップされなくなるので、予めクリップした文字列を作成してからHtmlを使用します。 * Htmlで修飾した文字列のクリップ [#j2842464] `Html`で文字列を修飾するとクリップされなくなるので、予めクリップした文字列を作成してから`Html`を使用します。 -&jnlp; -&jar; -&zip; - &jnlp; - &jar; - &zip; //#screenshot #ref(http://lh3.ggpht.com/_9Z4BYR88imo/TQTJP6CTKHI/AAAAAAAAAUE/aD5gF_0luwI/s800/ClippedHtmlLabel.png) #ref(https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTJP6CTKHI/AAAAAAAAAUE/aD5gF_0luwI/s800/ClippedHtmlLabel.png) **サンプルコード [#c0d8e028] ** サンプルコード [#c0d8e028] #code(link){{ class URLRenderer extends DefaultTableCellRenderer implements MouseListener, MouseMotionListener { private static Rectangle lrect = new Rectangle(); private static Rectangle irect = new Rectangle(); private static Rectangle trect = new Rectangle(); private int row = -1; private int col = -1; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, false, row, column); int mw = table.getColumnModel().getColumnMargin(); int rh = table.getRowMargin(); int w = table.getColumnModel().getColumn(column).getWidth(); int h = table.getRowHeight(row); Insets i = this.getInsets(); lrect.x = i.left; lrect.y = i.top; lrect.width = w - (mw + i.right + lrect.x); lrect.height = h - (rh + i.bottom + lrect.y); irect.x = irect.y = irect.width = irect.height = 0; trect.x = trect.y = trect.width = trect.height = 0; String str = SwingUtilities.layoutCompoundLabel( this, this.getFontMetrics(this.getFont()), value.toString(), //this.getText(), this.getIcon(), this.getVerticalAlignment(), this.getHorizontalAlignment(), this.getVerticalTextPosition(), this.getHorizontalTextPosition(), lrect, irect, //icon trect, //text this.getIconTextGap()); if(!table.isEditing() && this.row==row && this.col==column) { setText("<html><u><font color='blue'>"+str); }else if(hasFocus) { setText("<html><font color='blue'>"+str); }else{ setText(str); //setText(value.toString()); } return this; } //... }} **解説 [#l14757ca] -上 --setText("<html><font color='blue'>"+str); で文字列に下線を引く -下 --SwingUtilities.layoutCompoundLabelメソッドを使用して文字列をセル幅でクリップ --setText("<html><font color='blue'>"+str); で文字列に下線を引く ** 解説 [#l14757ca] - 上 -- `setText("<html><font color='blue'>"+str);`で文字列に下線を引く - 下 -- `SwingUtilities.layoutCompoundLabel`メソッドを使用して文字列をセル幅でクリップ -- `setText("<html><font color='blue'>"+str);`で文字列に下線を引く **参考リンク [#b6c3f45d] -[[JTableのセルにHyperlinkを表示>Swing/HyperlinkInTableCell]] ** 参考リンク [#b6c3f45d] - [[JTableのセルにHyperlinkを表示>Swing/HyperlinkInTableCell]] **コメント [#u9ec6110] ** コメント [#u9ec6110] #comment