Reputation: 3
In my Project i want to have a Table with items that may have subitems, like in the Eclipse 'Problems' View. (Indexes 2-17 should be Subitems of 1)
My Project so far: Overview of my Project
What i want to have:
Content of Main.java:
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
public class MainFrame extends JFrame {
private JPanel contentPane;
private JTable table;
public static void main(String[] args) {
MainFrame frame = new MainFrame();
frame.setVisible(true);
}
public MainFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout(0, 0));
table = new JTable(new CostumTableModel());
table.setFillsViewportHeight(true);
contentPane.add(table);
}
}
Content of CostumTableModel.java:
import javax.swing.table.AbstractTableModel;
public class CostumTableModel extends AbstractTableModel {
public CostumTableModel() {
}
@Override
public int getColumnCount() {
return 5;
}
@Override
public int getRowCount() {
return 5;
}
@Override
public Object getValueAt(int row, int col) {
if (col == 0) {
return row + 1;
}
return row * col;
}
}
Full Version of my Code, except this feature can be found at my Github. Does anybody of you know how to do this? I'm searching the whole day for a solution, but didn't find one.
Upvotes: 0
Views: 189