TableListBox header font


#1

Looks to me like a noob question, but for the life of me I can't figure out how to change the font for the header of a TableListBox... Thanks in advance for any help!


#2

Quickly searching through; would implementing TableHeaderComponent::LookAndFeelMethods::drawTableHeaderColumn() in your Look and Feel do the trick?

LookAndFeel_V2 overrides this method, if you need an example.


#3

Means that I need a LookAndFeel - I didn't feel the need to have one yet. Actually I just want to change the font size in my Table; if there's no simpler way I'll try that, thanks jrlanglois!


#4

Hi and sorry to necro this thread but I have the same issue.

Just want to change the header’s font to be plain instead of bold. Was hoping to be able to stay away from LookAndFeel since I haven’t had a need for it until now.

Reimplementing drawTableHeaderColumn() would mean having to manually draw the sorting indicators etc as well, correct?


#5
void LookAndFeel_V2::drawTableHeaderColumn (Graphics& g, TableHeaderComponent& header,
                                        const String& columnName, int /*columnId*/,
                                        int width, int height, bool isMouseOver, bool isMouseDown,
                                        int columnFlags)
{
auto highlightColour = header.findColour (TableHeaderComponent::highlightColourId);

if (isMouseDown)
    g.fillAll (highlightColour);
else if (isMouseOver)
    g.fillAll (highlightColour.withMultipliedAlpha (0.625f));

Rectangle<int> area (width, height);
area.reduce (4, 0);

if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
{
    Path sortArrow;
    sortArrow.addTriangle (0.0f, 0.0f,
                           0.5f, (columnFlags & TableHeaderComponent::sortedForwards) != 0 ? -0.8f : 0.8f,
                           1.0f, 0.0f);

    g.setColour (Colour (0x99000000));
    g.fillPath (sortArrow, sortArrow.getTransformToScaleToFit (area.removeFromRight (height / 2).reduced (2).toFloat(), true));
}

g.setColour (header.findColour (TableHeaderComponent::textColourId));
g.setFont (Font (height * 0.5f, Font::bold));
g.drawFittedText (columnName, area, Justification::centredLeft, 1);
}

This is the implementation of drawTableHeaderColumn.
In this second last line shows that JUCE sets the default font with style flag and font height.
So only way is by implementing TableHeaderComponent::LookAndFeelMethods::drawTableHeaderColumn() and set the looking feel to this for TableHeaderComponent.
Also notice that JUCE gives way to set the colourIds using TableHeaderComponent ::ColourIds.

So other option is JUCE should provide method for setting Font of TableHeaderComponent.