小编xxx*_*yyy的帖子

如何切换位置或交换两个JComboBox的内容?

我是JAVA GUI的新手,遇到了问题.下图显示了我的问题所在的GUI部分.

在此输入图像描述

我想实现这一点,当我点击"点击切换"按钮时,将交换comboBox的内容.我尝试了不同的方式来交换两个comboBox的位置或交换两个ComboBox的内容,但都没有成功.

以下是我的代码中与此问题相关的部分.

1类:

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPanel;

public class FilePathComboBox implements ActionListener {
    List<String> strings;
    BufferedReader input;
    JComboBox comboBox;
    JPanel jpFilePath;
    JButton testJB;

    public FilePathComboBox(String filePathOfSyncTool) {
        strings = new ArrayList<String>();
        FileReader fr;

        try {
            fr = new FileReader(filePathOfSyncTool);
        } catch (FileNotFoundException e1) {
            fr = null;
            e1.printStackTrace();
        }

        input = new BufferedReader(fr);
        try {
            String line = …
Run Code Online (Sandbox Code Playgroud)

java user-interface swing combobox jcombobox

4
推荐指数
1
解决办法
203
查看次数

标签 统计

combobox ×1

java ×1

jcombobox ×1

swing ×1

user-interface ×1