• Post Reply Bookmark Topic Watch Topic
  • New Topic

JColorChooser customization problem  RSS feed

 
S�bastien Vandamme
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I have a small problem with a JColorChooser.
I extend an AbstractColorChooserPanel to add a tab in a JColorChooser.
All work fine, but my problem is that my new ColorChooser has only a JList (in a JScrollPane), and that JList is placed in the middle of the chooser.



I try all the layout, but the JList don't move of her centered place.

What I want is that this list take all the available place of the chooser.
If someone can help me, please by advance,

Sebastien


I give you the code :


package com.dilogos.scenery;

import java.awt.BorderLayout;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;

import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.colorchooser.AbstractColorChooserPanel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class PredefinedColorPanel extends AbstractColorChooserPanel implements ListSelectionListener {
private static final long serialVersionUID = 4300877969577699414L;

Hashtable nameColor = new Hashtable();

public PredefinedColorPanel(String fileName) {
try {
FileReader fr = new FileReader(fileName);
BufferedReader buff = new BufferedReader(fr);
boolean eof = false;

String line = buff.readLine();

while(!eof) {
line = buff.readLine();
if(line == null) {
eof = true;
}else {
if(line != null && !line.contains("colorpalette")) {
int begin = line.indexOf("\"");
int end = line.indexOf("\"", begin + 1);

if(begin == -1 || end == -1) { return; }

String name = line.substring(begin + 1, end);
begin = line.indexOf("\"", end + 1) + 1; end = line.indexOf("\"", begin + 1);
int r = (new Integer(line.substring(begin, end))).intValue();
begin = line.indexOf("\"", end + 1) + 1; end = line.indexOf("\"", begin + 1);
int g = (new Integer(line.substring(begin, end))).intValue();
begin = line.indexOf("\"", end + 1) + 1; end = line.indexOf("\"", begin + 1);
int b = (new Integer(line.substring(begin, end))).intValue();
Color c = new Color(r, g, b);

nameColor.put(name, c);
}
}
}

buff.close();
} catch (FileNotFoundException fnfe) {
int i = JOptionPane.showConfirmDialog(this, "No predefined colord file found. Continue ?", "No predefined colors", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE);

if(i == 1) {
System.exit(0);
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}

public void updateChooser() {}

protected void buildChooser() {
setLayout(new BorderLayout());

DefaultListModel model = new DefaultListModel();
Enumeration colors = nameColor.keys();

while(colors.hasMoreElements()) {
model.addElement(colors.nextElement());
}

JList list = new JList(model);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(this);
JScrollPane jsp = new JScrollPane(list);

add(jsp, BorderLayout.EAST);
}

public void valueChanged(ListSelectionEvent e) {
Color newColor = (Color) nameColor.get(((JList)e.getSource()).getSelectedValue());
getColorSelectionModel().setSelectedColor(newColor);
}

public String getDisplayName() {
return "Predefined";
}

public Icon getSmallDisplayIcon() {
return null;
}

public Icon getLargeDisplayIcon() {
return null;
}
}
 
S�bastien Vandamme
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No one to help me ?
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Sebastien Vandamme
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, it works !!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!