I want to make a table that displays files loaded from a directory. I have a button that is clicked to open a file chooser and when the file is chosen it is pushed into a vector and then drawn to a call in the table. I am able to compile and run the program, I click the button to load, a file chooser appears but when I choose a file nothing happens, so I’m missing something. This is my first time doing something like this, so if anyone can suggest what is missing from my code? The table is visible I can see the headers, would it be better to draw empty cells first to be populated? Do i need a method to update the table somewhere else? There are no error messages, the program just continues to run, so something to do with displaying the file name isn’t right.
void TableComponent::loadToTable(juce::URL someFile)
{
for (auto i : fileNames)
{
fileNames.push_back(someFile.getFileName());
}
tableComponent.updateContent();
}
void TablesComponent::buttonClicked(Button* button)
{
if (button == &loadButton)
{
juce::FileChooser chooser{ "Select a file.." };
if (chooser.browseForFileToOpen())
{
loadToTable(juce::URL{ chooser.getResult() });
}
}
void TableComponent::paintCell(Graphics& g, int rowNumber, int columnId, int width, int height, bool rowIsSelected)
{
if (columnId == 1)
{
g.drawText(fileNames[rowNumber],
2, 0,
width - 4, height,
juce::Justification::centredLeft, true);
}
}