2016-11-12 7 views
0

JComboBox私はすべてのタイムゾーンを取得したいが、何も表示されないようにしようとしている。この問題に関して私を助けてくれる人はいますか?ここでタイムゾーンをJComboBoxに表示

は私のコードです:

public class Window extends JFrame { 
    private static final String DATE_FORMAT = "dd-M-yyyy hh:mm:ss a"; 
    public Window() { 
     super("Genesys"); 
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     setExtendedState(JFrame.MAXIMIZED_BOTH); 
     setSize(600, 470); 
     setVisible(true); 
     setLayout(null); 
     gradeCombo = new JComboBox <Object>(); 
     add(gradeCombo); 
     gradeCombo.setBounds(500, 100, 200, 20); 
     search.addActionListener(new csearch()); 
    } 
    class csearch implements ActionListener { 
     public void actionPerformed(ActionEvent event) { 
      SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT); 
      Date date = new Date(); 
      TimeZone tz = TimeZone.getDefault(); 
      pane.setBounds(10, 530, 760, 40); 
      pane1.setBounds(10, 260, 760, 40); 
      System.out.println("TimeZone : " + tz.getID() + " - " + tz.getDisplayName()); 
      System.out.println("TimeZone : " + tz); 
      System.out.println("Date (Ro - UTC+02:00) : " + formatter.format(date)); 
      date10.setText("Current time for Romania"); 
      date7.setText(String.valueOf("Time Zone : " + tz.getID() + " - " + tz.getDisplayName())); 
      date8.setText(String.valueOf("TimeZone : " + tz)); 
      date9.setText(String.valueOf("Date (Ro - UTC+02:00) : " + formatter.format(date))); 
      SimpleDateFormat sdfAmerica = new SimpleDateFormat(DATE_FORMAT); 
      SimpleDateFormat sdfParis = new SimpleDateFormat(DATE_FORMAT); 
      DateTime dt = new DateTime(date); 
      DateTimeZone dtZone = DateTimeZone.forID(country.getText()); 
      DateTime dtus = dt.withZone(dtZone); 
      TimeZone tzInAmerica = dtZone.toTimeZone(); 
      Date dateInAmerica = dtus.toLocalDateTime().toDate(); 
      gradeCombo = new JComboBox <Object> (TimeZone.getAvailableIDs()); 
     } 
    } 
} 

誰も私を助けてもらえますか?コンボボックスにタイムゾーンが表示されないのはなぜですか?

答えて

1

新しいJComboBoxをインスタンス化する代わりに、既存のコンボに適切なモデルを設定するだけです。

gradeCombo.setModel(new DefaultComboBoxModel<Object>(TimeZone.getAvailableIds())); 
関連する問題