我使用 Swing 和 WindowsBuilder,eclipse 环境在 unix 服务器上运行。
每次我运行程序并尝试将一些数据从另一个窗口复制粘贴到JTextField
程序中时,都会JTextField
停止响应。
我的意思是我在 Eclipse 中按播放,表单已启动并且JTextField
正在响应,但随后我按alt+tab 移动到另一个窗口,按ctrl+c然后alt+tab再次返回到正在运行的程序,但JTextField
没有任何响应。
帮助别人?
谢谢
那么这里是代码:
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.EventQueue;
import javax.swing.ButtonGroup;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.text.DefaultFormatter;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JCheckBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.text.DecimalFormat;
import javax.swing.JTextField;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.DropMode;
public class MainPage extends JFrame {
private JPanel contentPane;
private String sSpe1;
private String sSpe2;
private JTextField txtTomB1;
private JTextField txtTomB2;
private JTextField txtTomB3;
private JTextField txtTomB4;
private JTextField txtTomB5;
private JTextField txtPotB1;
private JTextField txtPotB2;
private JTextField txtPotB3;
private JTextField txtPotB4;
private JTextField txtPotB5;
private JTextField txtAraB1;
private JTextField txtAraB2;
private JTextField txtAraB3;
private JTextField txtAraB4;
private JTextField txtAraB5;
private JTextField[] arrTomBaits = new JTextField[5];
private JTextField[] arrPotBaits = new JTextField[5];
private JTextField[] arrAraBaits = new JTextField[5];
private JLabel lblNote;
private JLabel lblChooseLocation;
private JTextField txtLocation;
private JButton btnBrowse;
private boolean bCanContinue;
private JSpinner spinner;
private JSpinner spnRValueBelow;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainPage frame = new MainPage();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MainPage()
{
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 551, 609);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setSize(600, 1000);
setContentPane(contentPane);
contentPane.setLayout(null);
txtTomB1 = new JTextField();
txtTomB1.setDropMode(DropMode.INSERT);
txtTomB1.setBounds(20, 308, 86, 20);
contentPane.add(txtTomB1);
txtTomB1.setColumns(10);
arrTomBaits[0] = txtTomB1;
txtTomB2 = new JTextField();
txtTomB2.setDropMode(DropMode.INSERT);
txtTomB2.setColumns(10);
txtTomB2.setBounds(20, 339, 86, 20);
contentPane.add(txtTomB2);
arrTomBaits[1] = txtTomB2;
txtTomB3 = new JTextField();
txtTomB3.setDropMode(DropMode.INSERT);
txtTomB3.setColumns(10);
txtTomB3.setBounds(20, 370, 86, 20);
contentPane.add(txtTomB3);
arrTomBaits[2] = txtTomB3;
txtTomB4 = new JTextField();
txtTomB4.setDropMode(DropMode.INSERT);
txtTomB4.setColumns(10);
txtTomB4.setBounds(20, 401, 86, 20);
contentPane.add(txtTomB4);
arrTomBaits[3] = txtTomB4;
txtTomB5 = new JTextField();
txtTomB5.setDropMode(DropMode.INSERT);
txtTomB5.setColumns(10);
txtTomB5.setBounds(20, 432, 86, 20);
contentPane.add(txtTomB5);
arrTomBaits[4] = txtTomB5;
txtPotB1 = new JTextField();
txtPotB1.setDropMode(DropMode.INSERT);
txtPotB1.setColumns(10);
txtPotB1.setBounds(122, 308, 86, 20);
contentPane.add(txtPotB1);
arrPotBaits[0] = txtPotB1;
txtPotB2 = new JTextField();
txtPotB2.setDropMode(DropMode.INSERT);
txtPotB2.setColumns(10);
txtPotB2.setBounds(122, 339, 86, 20);
contentPane.add(txtPotB2);
arrPotBaits[1] = txtPotB2;
txtPotB3 = new JTextField();
txtPotB3.setDropMode(DropMode.INSERT);
txtPotB3.setColumns(10);
txtPotB3.setBounds(122, 370, 86, 20);
contentPane.add(txtPotB3);
arrPotBaits[2] = txtPotB3;
txtPotB4 = new JTextField();
txtPotB4.setDropMode(DropMode.INSERT);
txtPotB4.setColumns(10);
txtPotB4.setBounds(122, 401, 86, 20);
contentPane.add(txtPotB4);
arrPotBaits[3] = txtPotB4;
txtPotB5 = new JTextField();
txtPotB5.setDropMode(DropMode.INSERT);
txtPotB5.setColumns(10);
txtPotB5.setBounds(122, 432, 86, 20);
contentPane.add(txtPotB5);
arrPotBaits[4] = txtPotB5;
txtAraB1 = new JTextField();
txtAraB1.setDropMode(DropMode.INSERT);
txtAraB1.setColumns(10);
txtAraB1.setBounds(234, 308, 86, 20);
contentPane.add(txtAraB1);
arrAraBaits[0] = txtAraB1;
txtAraB2 = new JTextField();
txtAraB2.setDropMode(DropMode.INSERT);
txtAraB2.setColumns(10);
txtAraB2.setBounds(234, 339, 86, 20);
contentPane.add(txtAraB2);
arrAraBaits[1] = txtAraB2;
txtAraB3 = new JTextField();
txtAraB3.setDropMode(DropMode.INSERT);
txtAraB3.setColumns(10);
txtAraB3.setBounds(234, 370, 86, 20);
contentPane.add(txtAraB3);
arrAraBaits[2] = txtAraB3;
txtAraB4 = new JTextField();
txtAraB4.setDropMode(DropMode.INSERT);
txtAraB4.setColumns(10);
txtAraB4.setBounds(234, 401, 86, 20);
contentPane.add(txtAraB4);
arrAraBaits[3] = txtAraB4;
txtAraB5 = new JTextField();
txtAraB5.setDropMode(DropMode.INSERT);
txtAraB5.setColumns(10);
txtAraB5.setBounds(234, 432, 86, 20);
contentPane.add(txtAraB5);
arrAraBaits[4] = txtAraB5;
txtLocation = new JTextField();
txtLocation.setBounds(20, 492, 248, 20);
contentPane.add(txtLocation);
txtLocation.setColumns(10);
}
}
问题在于所有 txtARAB#、txtTomB#、txtPotB# 和 txtLocation