Swing/TableBorder のバックアップ(No.8)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/TableBorder へ行く。
- 1 (2018-06-12 (火) 09:53:59)
- 2 (2018-06-28 (木) 13:22:44)
- 3 (2020-06-10 (水) 13:43:45)
- 4 (2021-11-27 (土) 13:31:19)
- 5 (2022-12-26 (月) 00:33:45)
- 6 (2023-04-07 (金) 14:24:45)
- 7 (2023-10-31 (火) 14:51:45)
- 8 (2025-01-03 (金) 08:57:02)
- 9 (2025-01-03 (金) 09:01:23)
- 10 (2025-01-03 (金) 09:02:38)
- 11 (2025-01-03 (金) 09:03:21)
- 12 (2025-01-03 (金) 09:04:02)
- 13 (2025-03-03 (月) 12:02:43)
- 14 (2025-06-19 (木) 12:41:37)
- 15 (2025-06-19 (木) 12:43:47)
- category: swing folder: title: JTableの本体、ヘッダ、親JScrollPaneなどにBorderを設定する tags: [JTable, Border, JTableHeader, JScrollPane] author: aterai pubdate: 2018-06-11T15:29:35+09:00 description: JTableやその内部のJTableHeader、親のJScrollPaneやJViewportにそれぞれ異なるBorderを設定するテストを行います。 image: https://drive.google.com/uc?id=1QoXjiHkRpuR6I_IrsTRbEOcVi3-02nmReg
概要
JTableやその内部のJTableHeader、親のJScrollPaneやJViewportにそれぞれ異なるBorderを設定するテストを行います。
Screenshot

Advertisement
サンプルコード
JTable table = new JTable(new DefaultTableModel(15, 3));
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.getTableHeader().setBorder(
BorderFactory.createMatteBorder(0, 5, 0, 5, Color.ORANGE));
table.setBorder(BorderFactory.createLineBorder(Color.GREEN, 5));
JScrollPane scroll = new JScrollPane(table);
scroll.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
scroll.setViewportBorder(BorderFactory.createLineBorder(Color.RED, 5));
scroll.setBackground(Color.YELLOW);
scroll.getViewport().setBackground(Color.PINK);
table.setBackground(Color.WHITE);
table.getTableHeader().setBackground(Color.MAGENTA);
EventQueue.invokeLater(() -> {
JViewport vp = scroll.getColumnHeader();
vp.setOpaque(true);
vp.setBackground(Color.CYAN);
});
View in GitHub: Java, Kotlin解説
GREENJTable自体にJTable#setBorder(...)で線幅5pxのLineBorderを設定- セル内部に
LineBorderが入り込んでしまう
ORANGEJTableHeaderにJTableHeader#setBorder(...)で左右の幅が5pxのMatteBorderを設定
BLUE- 親
JScrollPaneにJScrollPane#setBorder(...)で線幅5pxのLineBorderを設定
- 親
RED- 親
JScrollPaneのJViewportにJScrollPane#setViewportBorder(...)で線幅5pxのLineBorderを設定 - セルの縦罫線が
JTableとJTableHeaderでズレてしまう
- 親
YELLOW- 親
JScrollPaneの背景色 JScrollBarが表示れる場合、その余白の背景色になる
- 親
PINK- 親
JScrollPaneの中央JViewportの背景色
- 親
WHITEJTableの背景色
MAGENTAJTableHraderの背景色WindowsLookAndFeelの場合、ヘッダーセルの縦罫線なる?
CYAN- 親
JScrollPaneのColumnHeader用JViewportの背景色 - 列ヘッダをドラッグしたあとのヘッダ背景色になる
- 親