I have a jtable inside jscrollpane. I use the jgoodies form form and put scrollpane on a line that is set to "pref". Here's what the table looks like right now:
I use swingx JXTable and set visibleRowCount to 2. But only half of the line is displayed.
When creating SSCCE, I realized that it does not work properly, because I have a custom TextAreaRenderer. I think that because of this renderer, the line height is not calculated properly. I am trying to understand why, at the same time, if you guys can notice that it will be great ...
public static void main(String[] args) { JFrame frame=new JFrame(); JPanel panel=new FormDebugPanel(); frame.setContentPane(panel); FormLayout layout=new FormLayout("1dlu:grow,200dlu:grow,1dlu:grow", "10dlu,pref,5dlu,pref,10dlu"); panel.setLayout(layout); String[] columns= {"1st Column","2nd Column","3rd Column"}; String[][] data= { {"Sethu","Data","Something\nis\nhere"}, {"Sethu","Data","Something\nis\nhere"}, }; JXTable table=new JXTable(data,columns); table.setVisibleRowCount(2); TableColumnModel columnModel=table.getColumnModel(); columnModel.getColumn(2).setCellRenderer(new TextAreaRenderer()); JScrollPane scrlPan=new JScrollPane(table); CellConstraints cc=new CellConstraints(); panel.add(scrlPan, cc.xy(2, 2)); panel.add(new JLabel("Label After Table"),cc.xy(2,4)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } }
And here is the visualization tool:
class TextAreaRenderer extends JTextArea implements TableCellRenderer { private final DefaultTableCellRenderer adaptee = new DefaultTableCellRenderer(); private final Map<JTable,Map<Integer,Map<Integer,Integer>>> cellSizes = new HashMap<JTable,Map<Integer,Map<Integer,Integer>>>(); public TextAreaRenderer() { setLineWrap(true); setWrapStyleWord(true); } public Component getTableCellRendererComponent(// JTable table, Object obj, boolean isSelected, boolean hasFocus, int row, int column) {
When I use TextAreaRenderer, then setVisibleRowHeight () is not executed properly. I think this is because you are not setting the line height in the renderer.