1

i have a panel(BorderLayout) with some labels and tables and want to show it via JOptionPane. Somehow the result does not look as i want. (see image)

JOptionPane with jtables

Here is the relevant code : ...

//init tablecontent
String[] obj_errColNames = {"WOC", "Error"};
String[][] obj_errTblData = new String[liFailFiles.size()][2];

n_entry = 0;
for(Entry<String,String> s : liFailFiles.entrySet()) {
obj_errTblData[n_entry][0] = s.getKey();
obj_errTblData[n_entry][1] = s.getValue();
n_entry++;
}
//add table into the panel
panel.add(new JScrollPane(tbl_err), BorderLayout.SOUTH);
tbl_err.setPreferredScrollableViewportSize(tbl_err.getPreferredSize());
tbl_err.setFillsViewportHeight(true); 

As you can see in the Image the text in the Error column is not displayed full. What can i do ?

TT.
  • 15,774
  • 6
  • 47
  • 88
CR92
  • 97
  • 1
  • 8
  • Your "relevant code" does not show how the JOptionPane is created. – Just another Java programmer Sep 10 '19 at 13:46
  • You can look at https://stackoverflow.com/questions/6447984/auto-resize-the-widths-of-jtables-columns-dynamically or https://stackoverflow.com/questions/17627431/auto-resizing-the-jtable-column-widths. Or, you can simply estimate the width using a JTextField: `tlb_err.getColumnModel().getColumn(1).setPreferredWidth(new JTextField(40).getPreferredSize().width);` – VGR Sep 10 '19 at 13:47
  • Using the text field to estimate will over estimate the size since it assumes the size of 40 "W" characters. So it would only be reasonable if you use a monospaced Font for the renderer of your JTable. See [Table Column Adjuster](https://tips4java.wordpress.com/2008/11/10/table-column-adjuster/) for the basics of determining the width of a columns based on its contained text. – camickr Sep 10 '19 at 14:55

0 Answers0