Swing/Html のバックアップ(No.18)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/Html へ行く。
- 1 (2004-07-05 (月) 10:15:47)
- 2 (2004-07-05 (月) 10:15:47)
- 3 (2004-07-07 (水) 02:01:50)
- 4 (2004-08-31 (火) 12:16:06)
- 5 (2004-10-08 (金) 06:23:08)
- 6 (2004-11-04 (木) 10:08:50)
- 7 (2005-04-28 (木) 04:33:07)
- 8 (2005-11-11 (金) 19:44:00)
- 9 (2006-02-16 (木) 22:18:25)
- 10 (2006-02-27 (月) 16:02:32)
- 11 (2007-04-07 (土) 01:18:46)
- 12 (2007-04-07 (土) 15:34:57)
- 13 (2007-05-22 (火) 13:50:31)
- 14 (2010-01-04 (月) 22:49:01)
- 15 (2010-05-30 (日) 00:26:16)
- 16 (2012-10-23 (火) 16:22:07)
- 17 (2013-04-10 (水) 16:06:06)
- 18 (2013-09-18 (水) 21:12:43)
- 19 (2013-09-28 (土) 21:35:44)
- 20 (2014-05-22 (木) 14:30:58)
- 21 (2014-11-01 (土) 00:46:09)
- 22 (2014-11-04 (火) 04:15:42)
- 23 (2015-03-04 (水) 17:19:46)
- 24 (2017-01-25 (水) 18:58:26)
- 25 (2017-04-04 (火) 14:17:08)
- 26 (2017-08-23 (水) 18:39:11)
- 27 (2017-11-02 (木) 15:34:40)
- 28 (2018-09-12 (水) 19:54:11)
- 29 (2019-05-22 (水) 19:34:28)
- 30 (2020-09-16 (水) 23:40:51)
- 31 (2022-04-07 (木) 15:53:15)
- 32 (2022-08-20 (土) 22:15:25)
- 33 (2022-10-04 (火) 15:51:49)
- 34 (2025-01-03 (金) 08:57:02)
- 35 (2025-01-03 (金) 09:01:23)
- 36 (2025-01-03 (金) 09:02:38)
- 37 (2025-01-03 (金) 09:03:21)
- 38 (2025-01-03 (金) 09:04:02)
- 39 (2025-06-19 (木) 12:41:37)
- 40 (2025-06-19 (木) 12:43:47)
TITLE:Htmlタグで文字列を修飾
Posted by aterai at 2004-07-05
Htmlタグで文字列を修飾
`Html
タグを使って
Swing
`コンポーネントで使用する文字列を修飾します。
- &jnlp;
- &jar;
- &zip;
サンプルコード
public class TestModel extends DefaultTableModel {
private static final String[] columnNames = {
"<html><p>No.</p><p><font color=blue>Number</font></p></html>",
"<html>Name<p><font color=\"red\">etc.</font></p></html>",
"<html><font color='green'>Comment</font></html>"
};
//......
View in GitHub: Java, Kotlin解説
上記のサンプルでは、`JTable
のヘッダと
JTabbedPane
のタブに
html
タグを使用しています。
<p>
`タグなどで簡単に改行するとこができます。
整形式になっていなくても、ある程度なら大丈夫なようです。属性も、エスケープした`"
や、
'
`で囲んでいなくても認識されます。
参考リンク
- How to Use Labels
- More About Handling Exceptions and Using HTML in Swing Components Tech Tips
- HTML.Tag (Java 2 Platform SE 5.0)
コメント
- メモ: Bug ID: 6670274 Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem) -- aterai
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class bug6670274x {
private static void createGui() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTabbedPane pane = new JTabbedPane();
pane.add("one", new JLabel("1"));
pane.add("<html>Title broken<BR>across 2 lines</html>", new JLabel("2"));
pane.add("three", new JLabel("3"));
JPanel p = new JPanel(new BorderLayout());
p.add(pane);
p.add(new JButton(new AbstractAction("setTitleAt: 0") {
@Override public void actionPerformed(ActionEvent e) {
pane.setTitleAt(0, "<html>setTitleAt:0<BR>xxxxx</html>");
}
}), BorderLayout.NORTH);
frame.add(p);
frame.setSize(640, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
@Override public void run() { bug6670274x.createGui(); }
});
}
}
- `
JDK 1.6.0_18
,
JDK 1.7.0
`で修正済: 6670274: Incorrect tab titles for JTabbedPane if using HTML (BasicTabbedPanelUI problem) -- aterai