I have a problem setting size and position of a TableListBoxModel. In this first screenshot, the Bottom TextButton shows where I want to place a TableListBoxModel:
This second screenshot shows a TableListBoxModel with exactly the same bounds, as specified by setBounds(), as the bottom TextButton in the first screenshot. The TableListBoxModel is too far down and too far to the right and is correspondingly truncated in both dimensions:
In this third screenshot, there are two TextButtons above the TableListBoxModel instead of just one. The vertical displacement and truncation of the TableListBoxModel is double compared with the second screenshot above:
The comments in this resize() code provide more detail on what seems to be happening:
void MainComponent::resized() {
constexpr bool showTopmostButton = true;
constexpr bool bottomComponentIsTableListBoxModel = true;
constexpr int defaultHeight = 36;
constexpr int defaultMargin = 30;
const int defaultWidth = getWidth() - defaultMargin * 2;
if (showTopmostButton) {
topmostButton.setBounds(
defaultMargin,
defaultMargin,
defaultWidth,
defaultHeight);
}
topButton.setBounds(
defaultMargin,
showTopmostButton
? topmostButton.getBottom() + defaultMargin
: defaultMargin,
defaultWidth,
defaultHeight);
const int tableY = topButton.getBottom() + defaultMargin;
// The table has to be tall to see any of it,
// as its bottom will be truncated!
constexpr int tableHeight = defaultHeight * 5;
if (bottomComponentIsTableListBoxModel) {
// If ONE button is shown above the TableListBoxModel,
// there's a gap the height of a button plus a default margin
// between the top of the table and where it should be,
// which is a default margin below the button above.
// And the bottom of the table is truncated.
// Also, the table's left margin is double what it should be,
// which is a default margin.
// If TWO buttons are shown above the TableListBoxModel,
// there's a gap twice the height of a button plus twp default
// margins between the top of the table and where it should
// be, which is a default margin below the button above.
// And the bottom of the table is truncated even more
// than when there is only one button above.
// The table's left margin is out by the same amount
// as when there is one button above.
tableListBoxModel.setBounds(
defaultMargin,
tableY,
defaultWidth,
tableHeight);
} else {
// If the bottom component is a button instead of a
// TableListBoxModel, there are no problems.
bottomButton.setBounds(
defaultMargin,
tableY,
defaultWidth,
tableHeight);
}
}