Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Forums
Register
Login
Java
»
Swing / AWT / SWT
bold font in last row of JTable
Wallace O'Connell
,
Greenhorn
Mar 12, 2004 09:53:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
I have created a JTable with some information. I want to have the last row of the table as a summary row so I want it to stand out. How would I go about putting the text in the last row of the table in bold font?
Thanks for help!
Jose Botella
,
Ranch Hand
Mar 12, 2004 11:17:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Welcome to the Ranch Wallace!
Try setting the font to bold only when the renderer is drawing the last row, as this example:
import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; import java.awt.*; import javax.swing.table.*; public class Table3 extends JFrame { Object[][] data = { { "1", "2", "3", "4", "5", "6" } , { "1", "2", "3", "4", "5", "6" }, {"1", "2", "3", "4", "5", "6"} }; Object[] header = { "A", "B", "C" , "D", "E", "F" }; static JTable table; Table3() { table = new JTable(data, header); getContentPane().add(new JScrollPane(table)); table.setDefaultRenderer(Object.class, new LastRowBold()); pack(); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { Table3 frame = new Table3(); } } class LastRowBold extends DefaultTableCellRenderer { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel parent = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if(row == table.getRowCount()-1) parent.setFont( parent.getFont().deriveFont(Font.BOLD)); return parent; } }
Post by:
autobot
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
This thread has been viewed 9590 times.
Similar Threads
JTable
Jtable focuslost
JTable
JTable scrolling
JTable(!!!)
More...
All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:44:09
.