| Summary: | Swing: It is not possible to enable a horizontal scroll bar in listboxes | ||
|---|---|---|---|
| Product: | z_Archived | Reporter: | Ivan Motsch <ivan.motsch> |
| Component: | Scout | Assignee: | Project Inbox <scout.core-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | lhu, zimmermann |
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
Added new api method for scout on eclipse 3.8.0:
IColumn.isAutoOptimizeWidth
IColumn.setAutoOptimizeWidth
AbstractColumn.getCOnfiguredAutoOptimizeWidth (boolean default false)
The listbox can do the following:
@Override
protected void execInitField() throws ProcessingException {
getTable().setAutoResizeColumns(false);
getTable().getColumns()[1].setAutoOptimizeWidth(true);
}
This feature only works inswing since swt does not offer an api to auto size the column (as by double clicking in the middle between two table columns)
If I understand correctly, the proposed solution to this ticket is a more elegant workaround as the one proposed by S. Schifferle. To enable a horizontal scrollbar on a listbox I still need to enable it on every listbox (or introduce my own AbstractListboxWithScrollbar and use it instead of AbstractListbox). Would it be possible to enable this feature on all listboxes by default (e.g. in AbstractListbox)? This is not necessary.
For every such project-specific "default" you are free to create your own template field:
public abstract class AbstractMyListBox extends AbstractListBox{
...
protected void execInitField...{
}
}
Instead of the basic AbstractListBox you then use the AbstractMyListBox wherever you need that listbox.
This is called "adding a template layer". When there are already many such fields in your project, then simply do a search/replace and you have your template layer.
Ok, I understand how to create a template layer. I still think it would be good if no such template layer is necessary and it would be the default behavior of any listbox to show a horizontal scrollbar (only if needed). The length of the listbox content is often not known to the programmer (e.g. content read from a database, texts defined by an application user etc.). In these cases a horizontal scrollbar is certainly appreciated by the application user. So I think all applications could profit from such a default behavior of a listbox. Unfortunately this feature is only possible in Swing, not SWT. Swt offers no api to make a column "optimal" sized. Even though the double click between two columns does that natively. Also when used in swing the horizontal grid lines are not anymore drawn on the full width when the listbox is wider than its "optimal" width. And not to forget existing code that is optimized to have listbox height that matches its item count. This change of default would break their code. These drawbacks together with the easy way of adding a template layer make it almost mandatory to keep the current default as default and to recommend to you to add that template layer to your project. Please note that we are not talking about a feature that does not exist but just about changing an existing default behaviour. The possibility to have your desired functionality is added in 3.7.0+ Ok, thanks for your feedback. changed status from closed to resolved fixed. bugs are cloesd only after a specific release is shipped. ticket closed. deliverd as part of eclipse scout 3.8.0 (juno release train) |
[on behalf of Sandro Schifferle, BSI AG] When a listbox contains long entries they are not readable. In our own project we used the following workaround; @Override protected void execInitField() throws ProcessingException { /* set autoResizeColumns off */ getTable().setAutoResizeColumns(false); /* resize the column to the label size*/ JLabel l = new JLabel(); int pix_max = 0; for (ITableRow tableRow : getTable().getRows()) { if (tableRow.isFilterAccepted()) { /* filter inactive rows */ if (l.getFontMetrics(l.getFont()).stringWidth(tableRow.getCell(1).getText()) > pix_max) { pix_max = l.getFontMetrics(l.getFont()).stringWidth(tableRow.getCell(1).getText()); } } } /* + 30 is because of the checkbox */ pix_max += 30; if (pix_max > getTable().getColumnSet().getColumn(1).getInitialWidth()) { getTable().getColumnSet().getColumn(1).setWidth(pix_max); } }