How to highlight a whole row of data in JTable?

I perform the message function, and I want to boldly highlight the path where "read = No", and after I click on it, it will become read = yes, and unbold ... I already made part of the database, but I'm serious don't know how to make a rendering table .... cauze i'm still very fresh in java ... so can anyone help? appreciates a lot!

+3
source share
3 answers

you can do it using HTML

String str = "<html><b>this is bold</b> this is normal </html>";
+9
source

I want to boldly highlight the road where "read = No", and after I click on it, it will become read = yes, and unbold ...

Table Row Rendering . , :

c.setFont(  c.getFont().deriveFont(Font.BOLD) );
+5

, - ( ). /, ( 4- ), script/program ( ). , , . , , , , DefaultCellRenderer, , ( , ). "Keep It Simple Stupid" (KISS ) ... , - .

        for(int r=0;r<table.getRowCount();r++) {
            if(!table.getValueAt(r, 2).equals(table.getValueAt(r, 3))) {
                for(int c=0;c<table.getColumnCount();c++) {
                    table.setValueAt("<html><b>" + table.getValueAt(r, c) + "</b></html>", r, c);
                }
            }
        }

I'm sure there are other, more efficient methods ... but that was what I was able to come up with my (still limited) Java knowledge that really worked in my situation. Again, sorry to revive the old post, but I hope this helps some others in similar situations for my own.

+2
source

Source: https://habr.com/ru/post/1783467/


All Articles