我的文本文件是這樣的:爪哇 - 如何填寫組合框與txt文件的某個部分
Jordan|Turner|jotu|12345|Department of Complaints|Belgrade|
Travis|Bickle|trabic|54321|Driving Department|Novi Sad|
而且這樣的代碼:
package gui;
public class ReservationWindow extends JFrame {
private JComboBox cbDispatcher;
private JLabel lblDispatcherecer;
public ReservationWindow() {
setTitle("Reservations");
ImageIcon ikonica = new ImageIcon
(LoginProzor.class.getResource("/ikonice/faketaxi.png"));
setIconImage(ikonica.getImage());
setSize(400, 350);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
setResizable(false);
initGUI();
initActions();
}
private void initActions() {
//here is everything fine :D
}
private void initGUI() {
MigLayout mig = new MigLayout("wrap 2", "[][]", "[]10[][]10[]");
setLayout(mig);
cbDispatcher = new JComboBox();
lblDispatcher = new JLabel("Dispatcher with whom you talked");
add(lblDispatcher);
add(cbDispatcher);
}
}
現在,如何與某一部分填充的ComboBox這個linse? (在這種情況下,與第四部分 - 投訴部和駕駛部)
通過'讀取該文件,然後分割字符串'|',這樣會得到數組然後使用方法中'jComboBox'加推崇的價值觀'的addItem ()' – Amogh
@Amogh是的,我理解邏輯,並嘗試用BufferReader等讀取文件,並嘗試了很多方法,但我不確定如何以正確的方式讀取和分割文件。 –
@Amogh 1.8.0_91 –