0

Hi I am doing a lab where I have to print out all of the locales when the JButton is pressed but when I run the program all it does is show the Vietnamese locale anyone any suggestions how to show them ALL ?

import java.awt.*;

import javax.swing.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.*;

public class LocalesList extends JFrame implements ActionListener {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	JButton LocaleButton = new JButton("LocaleList");

	JTextArea LocaleList1 = new JTextArea(20 , 20);

	
	public LocalesList(){
		
		super("Locale list");//build the gui

		Container GuiCont = getContentPane();

		JPanel LocalePanel = new JPanel();
		
		LocalePanel.add(LocaleButton);
		
		LocalePanel.add(LocaleList1);
		
		GuiCont.add(LocalePanel);
		
		setSize(600, 600);
		setVisible(true);
		
		LocaleButton.addActionListener(this);
		
	}
	
	public void actionPerformed(ActionEvent e) {
		
		

        if(e.getSource() == LocaleButton){
        	
        	Locale list[] = SimpleDateFormat.getAvailableLocales();
            Set set = new TreeSet();
            
        	for (int i = 0; i < list.length; i++) {
                set.add(list[i].getDisplayName() +"\t\t\t:\t"+ list[i].toString());
            }
            Iterator it = set.iterator();
            while (it.hasNext()) {
                LocaleList1.setText((String) it.next() );
            }

        	
        	
        	
        }
		
		
		
	}
	
	
	public static void main(String[]args){
		
		LocalesList tryit = new LocalesList();
		
		
	}
	
	
	
}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by moutanna
0

Hi
Use upend instead of setText:

while (it.hasNext()) {
                LocaleList1.append((String) it.next());
              //  LocaleList1.insert((String) it.next()) ;
            }

hope it helps

0

using insert is also possible with the syntaxe lik this

LocaleList1.insert((String) it.next(),LocaleList1.getText().length()) ;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.