Word wrap in JList items?

Yep, using Andrew's code, I came up with something like this.

Yep, using Andrew's code, I came up with something like this: import java.awt. Component; import javax.swing. *; public class JListLimitWidth { public static void main(String args) { String names = { "John Smith", "engelbert humperdinck", "john jacob jingleheimer schmidt" }; MyCellRenderer cellRenderer = new MyCellRenderer(80); JList list = new JList(names); list.

SetCellRenderer(cellRenderer); JScrollPane sPane = new JScrollPane(list); JPanel panel = new JPanel(); panel. Add(sPane); JOptionPane. ShowMessageDialog(null, panel); } } class MyCellRenderer extends DefaultListCellRenderer { public static final String HTML_1 = ""; public static final String HTML_3 = ""; private int width; public MyCellRenderer(int width) { this.

Width = width; } @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String text = HTML_1 + String. ValueOf(width) + HTML_2 + value.toString() + HTML_3; return super. GetListCellRendererComponent(list, text, index, isSelected, cellHasFocus); } }.

1 hmmmm how easy – mKorbel Nov 19 at 21:23 It wasn't my smarts that did this but this one here: Andrew's post. I can't upvote his answer more than once, but I encourage anyone who thinks that my answer was helpful to upvote the link. – Hovercraft Full Of Eels Nov 19 at 21:27 Great!

I suggest we upvote both! – Costis Aivalis Nov 19 at 21:32 +1 nice example. :) – Andrew Thompson Nov 20 at 0:51 (as you all know, including @Andrew Thompson, I don't like html tricksing overly much, especially not if mis-used for hard-coded sizing ) so, why not use the actual with of the list instead of the fixed?

– kleopatra Nov 20 at 11:52.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions