这段代码调出了一个 Jframe,里面有我的“Paneltest”jpanel。
面板测试有一个文本字段和一个按钮,用于启动网页,其中包含 URL 末尾文本字段中的任何内容,即 IE (www.website.com/textfield)
当网页启动时,它会将焦点从 jframe 上移开,到目前为止我试图重新调整它的方法都没有奏效。
JFrame f = new JFrame("KioskApp");
f.setSize(800, 600);
Paneltest Paneltest = new Paneltest();
f.add(Paneltest);
f.setVisible(true)
我尝试用 while 语句包围这段代码,并在末尾添加 f.dispose 和 Thread.sleep(x) 以使其关闭框架并在几秒钟后再次启动它,但它导致 Paneltest 没有出现在框架。
每当我添加一个while循环时,它都会阻止Paneltest出现,因此我无法测试其他方法,如f.toFront或f.requestfocus。
我要添加什么以使其永久重新聚焦或正确重新启动 Jframe。
编辑:这就是我现在所处的位置。
如果我添加 マルちゃん だよ 建议的代码,那么所发生的只是任务栏中框架突出显示的选项卡。
前线
package kioskapp;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
/**
*
* @author jorent
*/
public class BringToFront {
JFrame frame;
Timer timer;
public BringToFront(JFrame frame) {
this.frame = frame;
timer = new Timer();
timer.schedule(new ToFrontTask(), 5000);
}
class ToFrontTask extends TimerTask {
@Override
public void run() {
frame.toFront();
frame.repaint();
}
}
}
这是我实现需要重新聚焦的 Jframe 的代码片段
初始设置窗格
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
JFrame f1 = new JFrame("KioskApp");//initializes frame to open the panel
f1.setSize(650, 400);// Functionless setting of the size, I used it to approximate the size of the destination screen
Paneltest Paneltest = new Paneltest();//initializes Panel to be put in the fram
f1.add(Paneltest);// puts the panel in the fram
f1.setUndecorated(true);// Removes the ability to mess with the screen
f1.setVisible(true);//makes the frame visible
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// When not fullscreen(not a possibility now) changes the (X) button to close instead of hide the frame
f1.setExtendedState(JFrame.MAXIMIZED_BOTH);// Fullsc
new BringToFront (f1);
}
如果我将 .alwaysontop 添加到前面,它将起作用,但我不允许我在不单击窗口的情况下在框架的文本字段中输入任何内容(最终用户将禁用单击,因此这将不起作用)。