Re: choosing linestyles with a combobox



Tomba wrote:
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);
}
}

nevermind I've solved it ;) Just replacing the JLabel by JPanel

anyway... that was trial and error, could anyone explain that?
.



Relevant Pages

  • choosing linestyles with a combobox
    ... I'm trying to let a user choose a linestyle by selecting one out of a combobox. ... I try to display a preview line in each item of the combo. ... private class LineCellRenderer extends JLabel implements ListCellRenderer { ...
    (comp.lang.java.gui)
  • Passing events between forms
    ... If I call a form as a result of selecting a menu option, ... form to be able to detect whether the user selected Certificate or Category ... use public variables, as you're supposed to keep everything as private as ...
    (microsoft.public.dotnet.framework.adonet)
  • RE: a bit of vba, a bit of sql
    ... number from the combobox 'indirectly' by selecting the patient's name. ... > to be MR_Number in your case) as the Control Source Property. ... > See http://www.QBuilt.com for all your database needs. ...
    (microsoft.public.access.formscoding)
  • Re: Databound combobox, new and selected value confusion.
    ... The SelectionChangeCommitted event for the combobox occurs before the ... Member are both bound to ProjectName, which is the column in the ... then the call to EndEditproduces an exception: ... The intention of selecting items in the combobox is that this effects ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Using SQL to create user defined table & column names
    ... I want to be able to select the table from a combobox in the VB6 form. ... on selecting the appropriate column name how does one edit this i.e ... > I have been able to do this using standard SQL statements ...
    (microsoft.public.data.ado)