Code example for JLabel

Methods: getFontgetText

0
 
        JTable table = new JTable(model);
        TableCellRenderer renderer = new SudokuCellRenderer();
 
        JLabel cell1 = (JLabel) renderer.getTableCellRendererComponent(table, '1', false, false, 0, 0);
        assert cell1.getText().equals("1") : "Wrong text at cell 1: " + cell1.getText();
        assert cell1.getFont().isBold() : "Fixed cells should be rendered in bold.";
        JLabel cell2 = (JLabel) renderer.getTableCellRendererComponent(table, '2', false, false, 0, 1);
        assert cell2.getText().equals("2") : "Wrong text at cell 2: " + cell2.getText();
        assert cell2.getFont().isBold() : "Fixed cells should be rendered in bold.";
        // Check an empty cell, it should have no text. 
        JLabel cell3 = (JLabel) renderer.getTableCellRendererComponent(table, null, false, false, 0, 2);
        assert cell3.getText().length() == 0 : "Wrong text at cell 3: " + cell3.getText();
    } 
 
 
    @BeforeClass 
    public void createTable() 
    { 
        SudokuTableModel model = new SudokuTableModel();