title image


Smiley Re: JList: Ausgewähltes Element größer darstellen
Henrik hat mal wieder die einzig wahren Ideen ;-)Ich habe das mal so probiert:import java.awt.*;import javax.swing.*;import javax.swing.plaf.basic.*;public class ListCellRendererTest { static boolean cellIsSelected; public static void main(String[] args) { JFrame frame = new JFrame("ListCellRendererTest"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 300); String listEntries[] = {"Element 1", "Element 2", "Element 3", "Element 4"}; JList list = new JList(listEntries); list.setCellRenderer(new MyListCellRenderer()); list.setUI(new MyListUI()); JScrollPane scrollPane = new JScrollPane(list); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setVisible(true); } static class MyListCellRenderer implements ListCellRenderer { private DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer(); public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent (list, value, index, isSelected, cellHasFocus); renderer.setText(value.toString()); if (isSelected) { cellIsSelected=true; renderer.setFont(new Font(list.getFont().getName(), Font.PLAIN, list.getFont().getSize() * 3)); Dimension dim= new Dimension(100,40); renderer.setMaximumSize(dim); renderer.setMinimumSize(dim); renderer.setPreferredSize(dim); } else { cellIsSelected=false; renderer.setFont(list.getFont()); } return renderer; } } static class MyListUI extends BasicListUI { public Rectangle getCellBounds(JList list, int index1, int index2) { System.out.println(cellIsSelected+" "+index1+" "+index2); Rectangle r= super.getCellBounds(list, index1, index2); if (cellIsSelected) r.setBounds(r.x, r.y-10, r.width, r.height+20); return r; } }}Klappt allerdings hinten und vorne nicht.



geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: