choosing linestyles with a combobox
- From: Tomba <tomba@xxxxxxxxxxxxxxx>
- Date: Sat, 26 Nov 2005 16:16:35 +0100
hi,
I'm trying to let a user choose a linestyle (that is several predefined dash patterns) by selecting one out of a combobox. I try to display a preview line in each item of the combo.
The problem here is that only the selected element is painted and visible, while the dropdown list displays nothing.
Here's my cell renderer, I hope anyone knows something to solve this one. I suspect paint() is only done for the selected item but I have no clue how to solve it :(
Thanks!
private class LineCellRenderer extends JLabel implements ListCellRenderer {
private float[] value;
private JTextField width;
public LineCellRenderer(JTextField width) {
super();
setOpaque(true);
this.width = width;
}
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
this.value = (float[])value;
return this;
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
super.paint(g);BasicStroke bStroke = new BasicStroke(Integer.valueOf(width.getText()), BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 5, value, 0);
Line2D line = new Line2D.Double(2, getHeight()/2, getWidth()-4, getHeight()/2);
g2.setColor(Color.BLACK);
g2.setStroke(bStroke);
g2.draw(line);
}
}
.
- Follow-Ups:
- Re: choosing linestyles with a combobox
- From: Tomba
- Re: choosing linestyles with a combobox
- Prev by Date: Re: size of a string in pixel ?
- Next by Date: Re: choosing linestyles with a combobox
- Previous by thread: size of a string in pixel ?
- Next by thread: Re: choosing linestyles with a combobox
- Index(es):
Relevant Pages
|
|