I have a few questions related to JTables so bear with me and if you could answer what you know, it would be appriecated.
My GUI has a few components, but 2 main ones.
1. A JList of "Chart" Objects. A "Chart" Object contains String Data Range, String Title, String Left Axis Label, String Bottom Axis Label, String Type, and ArrayList<SeriesInfo> list of series. (Those are obviously not their variable names). A "SeriesInfo" Object contains String Name, Point Start, Point End, String DataLabel, String DataRange, Color SeriesColor, and boolean PrimaryAxis.
2. A JTable with 5 columns. The data for those columns are, 1) String, 2) String, 3) CheckBox, 4) Color Picker/Background Colored, 5) String.
Apart from those, there are 3 JToggleButtons and 3 JTextFields.
How this is going to work is that when the user selects a Chart from the JList, it will update the 3 JToggleButtons, 3 JTextFields, and the JTable. The content of the JTable will be the Chart Object's SeriesInfo objects. So when the user selects a Chart from the JList, the JTable will need to dynamically change row count and add new data. The columns will get their data from the following: 1) SeriesInfo.Name, 2) SeriesInfo.DataRange, 3) SeriesInfo.PrimaryAxis, 4) SeriesInfo.SeriesColor, 5) SeriesInfo.DataLabel.
So, now that you are familiar with my design, here are my JTable questions:
1. How can I make the size of the JTable dynamically? The number of the Rows of the JTable will depend on the the length of the SeriesInfo ArrayList of the Chart Object. My current design makes a statically sized JTable.
2. How can I make the boolean CheckBox an actual CheckBox? At first I just had the true/false value, then I played around on Google and got the CheckBox to show instead of the text, but when you click in the CheckBox is just turns back into text and I get a bunch of errors about parsing the String when you try to click out of it.
3. How can I open a Color Picker Pop-up when the user clicks in a cell in the 4th column? I assume I need an ActionListener of some sorts, but I'm not sure where to go with it.
I think thats everything, I will continue to ask questions as I go.
My current JTable code (which I got from playing around on Google and trying things out will need some major overhaul) is this:
String[] columnNames = {"Data Name", "Data Range", "Primary Axis", "Color", "Data Label"}; Object[][] data = { {"DataName", "A3:A25", new Boolean(false), "Color Picker", "Label"} }; final JTable table = new JTable(data, columnNames); table.getColumnModel().getColumn(2).setCellRenderer(new TableCellRenderer() { public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected,boolean isFocused, int row, int col) { boolean marked = (Boolean) value; JCheckBox rendererComponent = new JCheckBox(); if (marked) { rendererComponent.setSelected(true); } return rendererComponent; } }); JScrollPane tableScroller = new JScrollPane(table); tableScroller.setPreferredSize(new Dimension(400, 70));