import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JTextField;
public class TabRendererDemo extends JFrame {
public TabRendererDemo() {
JList list = new JList(new Object[] {"Hier\tTab\t\tda\tTab", "\t\tTab\t\t\tTab"});
list.setCellRenderer(new TabRenderer());
this.getContentPane().add(list);
}
class TabRenderer extends DefaultListCellRenderer {
JTextField field = new JTextField();
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus){
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
field.setText(super.getText());
field.setFont(super.getFont());
field.setBackground(super.getBackground());
field.setForeground(super.getForeground());
field.setBorder(super.getBorder());
return field;
}
}
public static void main(String[] args) {
JFrame frame = new TabRendererDemo();
frame.setBounds(0, 0, 500, 300);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}