package sortByTab;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JList;
public class sortByTab extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTabbedPane jTabbedPane = null;
private JList jList = null;
private String[] name = {"Alfred Hitchcock","Yoko Ono","Selma Hayek","Steven Seagal","Al Bundy","von Hindenburg","Vanessa"};
public sortByTab() {
super();
initialize();
}
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJTabbedPane(), BorderLayout.CENTER);
}
return jContentPane;
}
private JTabbedPane getJTabbedPane() {
if (jTabbedPane == null) {
jTabbedPane = new JTabbedPane();
jTabbedPane.addTab("Liste", null, getJList(), null);
for(int i=0;name.length>i;i++)if(Character.isLowerCase(name[i].charAt(0)))
name[i]=String.valueOf(name[i].toUpperCase().charAt(0)) + name[i].substring(1);
java.util.Arrays.sort(name);
boolean empty = true;
for(int i=0;name.length>i;i++){
for(int n=1;jTabbedPane.getTabCount()>n;n++){
empty = true;
if(name[i].toUpperCase().charAt(0)==jTabbedPane.getTitleAt(n).toUpperCase().charAt(0))
empty = false;
}
if(empty)jTabbedPane.addTab(
String.valueOf(name[i].toUpperCase().charAt(0)),
null, getList(name[i].toLowerCase().charAt(0)), null );
}
}
return jTabbedPane;
}
private JList getJList() {
if (jList == null) {
jList = new JList(name);
}
return jList;
}
private JList getList( Character c ) {
String[] List = new String[name.length];
int n = 0;
for(int i=0;name.length>i;i++)
if(name[i].toLowerCase().charAt(0)==Character.toLowerCase(c))
List[n++]=name[i];
return new JList(List);
}
}