我似乎对我的文件选择器对话的非常简单的实现有一个问题,这需要我每次都要最小化Netbeans才能到达它,并且特别是现在通过测试它变得非常令人沮丧.
我已经在网上看到了一些解决方案,包括SO,但似乎没有一个可以做到这一点,而其他一些解决方案对我目前的水平看起来非常冗长和复杂.
private void fileSearch() {
JFileChooser fileSelect = new JFileChooser();
int returnVal = fileSelect.showOpenDialog(null);
String pathToFile;
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fileSelect.getSelectedFile();
pathToFile = file.getAbsolutePath();
try {
P.binaryFileToHexString(pathToFile);
} catch (Exception e) {
System.out.print("Oops! there was an error there..." + e);
}
System.out.println("\nYou chose to open this file: " + file.getName());
}
}
Run Code Online (Sandbox Code Playgroud)
我的一些尝试包括使用;
.requestFocus();
.requestFocusInWindow();
.setVisible();
Run Code Online (Sandbox Code Playgroud)
我可以设置一个特定的属性/方法来解决问题吗?
我想在JPanel中画一条线.这是我的GUI,我希望JPanel中的一行是白色的.

我找到很多例子,但问题是如何使用它.
在许多例子中,他们总是画一个从JPanel扩展的JFrame.
我想将面板添加到框架中并添加一些按钮以在多个方向上绘制线条,并使用中心的X按钮来清洁JPanel.
这是界面的代码:
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class circuit extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
circuit frame = new circuit();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public …Run Code Online (Sandbox Code Playgroud)