use of javax.swing.DefaultListModel in project jdk8u_jdk by JetBrains.
the class bug8057791 method main.
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(new NimbusLookAndFeel());
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
final int listWidth = 50;
final int listHeight = 50;
final int selCellIndex = 0;
JList<String> list = new JList<String>();
list.setSize(listWidth, listHeight);
DefaultListModel<String> listModel = new DefaultListModel<String>();
listModel.add(selCellIndex, "E");
list.setModel(listModel);
list.setSelectedIndex(selCellIndex);
BufferedImage img = new BufferedImage(listWidth, listHeight, BufferedImage.TYPE_INT_ARGB);
Graphics g = img.getGraphics();
list.paint(g);
g.dispose();
Rectangle cellRect = list.getCellBounds(selCellIndex, selCellIndex);
HashSet<Color> cellColors = new HashSet<Color>();
int uniqueColorIndex = 0;
for (int x = cellRect.x; x < (cellRect.x + cellRect.width); x++) {
for (int y = cellRect.y; y < (cellRect.y + cellRect.height); y++) {
Color cellColor = new Color(img.getRGB(x, y), true);
if (cellColors.add(cellColor)) {
System.err.println(String.format("Cell color #%d: %s", uniqueColorIndex++, cellColor));
}
}
}
Color selForegroundColor = list.getSelectionForeground();
Color selBackgroundColor = list.getSelectionBackground();
if (!cellColors.contains(new Color(selForegroundColor.getRGB(), true))) {
throw new RuntimeException(String.format("Selected cell is drawn without selection foreground color '%s'.", selForegroundColor));
}
if (!cellColors.contains(new Color(selBackgroundColor.getRGB(), true))) {
throw new RuntimeException(String.format("Selected cell is drawn without selection background color '%s'.", selBackgroundColor));
}
}
});
} catch (UnsupportedLookAndFeelException | InterruptedException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
use of javax.swing.DefaultListModel in project OpenAM by OpenRock.
the class ListJPanel method addCategory.
public void addCategory(ImageListEntry entry) {
ListModel model = categoryjList.getModel();
if (model instanceof DefaultListModel) {
((DefaultListModel) model).addElement(entry);
} else {
DefaultListModel newModel = new DefaultListModel();
newModel.addElement(entry);
categoryjList.setModel(newModel);
}
}
use of javax.swing.DefaultListModel in project SIMRacingApps by SIMRacingApps.
the class JListBinding method get.
public void get(IValidatable bean) {
try {
DefaultListModel model = (DefaultListModel) _list.getModel();
final int size = model.getSize();
List<Object> list = new ArrayList<Object>(size);
for (int i = 0; i < size; i++) {
list.add(model.get(i));
}
PropertyUtils.setProperty(bean, _property, list);
} catch (Exception e) {
throw new BindingException(e);
}
}
use of javax.swing.DefaultListModel in project SIMRacingApps by SIMRacingApps.
the class JListBinding method put.
public void put(IValidatable bean) {
try {
DefaultListModel model = new DefaultListModel();
List<?> list = (List<?>) PropertyUtils.getProperty(bean, _property);
if (list != null) {
for (Object o : list) {
model.addElement(o);
}
}
_list.setModel(model);
} catch (Exception e) {
throw new BindingException(e);
}
}
use of javax.swing.DefaultListModel in project ACS by ACS-Community.
the class BeanGrouper method getStatusScrollBar.
private JScrollPane getStatusScrollBar() {
model = new DefaultListModel();
if (statusList == null) {
statusList = new JList(model);
model.addElement("Status: Sampling Group ready to start.");
}
if (statusScrollBar == null) {
statusScrollBar = new JScrollPane(statusList);
}
statusList.setVisibleRowCount(1);
statusScrollBar.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
return statusScrollBar;
}
Aggregations