0
我在製作Java桌面應用程序。在我的應用程序中,我使用了JCombobox。這裏有一個例子:JCombobox隱藏第一個對象的名稱並根據用戶輸入進行編輯
我沒寫東西了JCombobox
。但是,第一部電影的名字可以從JComboBox
可以看出。
此外,應用程序接受來自用戶的輸入並根據該輸入向JCombobox
寫入內容。
public class Searchbar extends JComboBox
{
// PROPERTIES
AutoCompleteDecorator decorator;
private final ArrayList<Movie> movies;
private final DBConnectMovie movieConnection = new DBConnectMovie();
private final int totalCount = movieConnection.getTotalMovieCount();
private String item;
// CONSTRUCTOR
public Searchbar()
{
movies = movieConnection.getAllMovies();
this.insertItemAt("", 0);
this.setModel(new DefaultComboBoxModel(movies.toArray()));
AutoCompleteDecorator.decorate(this);
this.setPreferredSize(new Dimension(500, 40));
item = this.getEditor().getItem().toString();
}
// METHODS
public void changeComboBoxText()
{
System.out.println("Prints this out");
this.getEditor().setItem("C");
}
}
我可以打印出changeComboBox
方法中的文字。但是,我無法設法更改JComboBox
的文本。
祝您有美好的一天,謝謝!
'this.setModel(新DefaultComboBoxModel(movies.toArray()));''引起渲染JComboBox'無論你在'movies' – c0der
但是,如果沒有那我怎麼會告訴用戶JComboBox的內容? –