当前位置: 技术问答>java相关
JInternalFrame 一打开的时候,怎样改变焦点?
来源: 互联网 发布时间:2015-09-19
本文导语: 有没有人知道怎样可以令 JInternalFrame 一打开的时候, 人为控制某个组件(如JButton、JTextField)立刻得到焦点? 如下程序好像就不奏效: this.addInternalFrameListener(new InternalFrameAdapter() { public void intern...
有没有人知道怎样可以令 JInternalFrame 一打开的时候,
人为控制某个组件(如JButton、JTextField)立刻得到焦点?
如下程序好像就不奏效:
this.addInternalFrameListener(new InternalFrameAdapter()
{ public void internalFrameOpened(InternalFrameEvent e )
{ jButton1.requestFocus();
}
});
请问各位大侠如何是好?
人为控制某个组件(如JButton、JTextField)立刻得到焦点?
如下程序好像就不奏效:
this.addInternalFrameListener(new InternalFrameAdapter()
{ public void internalFrameOpened(InternalFrameEvent e )
{ jButton1.requestFocus();
}
});
请问各位大侠如何是好?
|
very easy
import javax.swing.*;
import javax.swing.event.*;
class QQQ extends JFrame
{
JDesktopPane desk = new JDesktopPane();
JInternalFrame if1 = new JInternalFrame();
JButton bt1 = new JButton("button1");
JButton bt2 = new JButton("button2");
QQQ()
{
setContentPane(desk);
desk.add(if1);
JPanel p = new JPanel();
p.add(bt1);
p.add(bt2);
if1.getContentPane().add(p);
if1.addInternalFrameListener(new MyListener());
if1.reshape(10,10,100,100);
if1.setVisible(true);
setBounds(100,100,400,400);
setVisible(true);
}
public static void main(String[] args)
{
new QQQ();
}
class MyListener extends InternalFrameAdapter
{
public void internalFrameActivated(InternalFrameEvent e )
{
bt1.requestFocus();
}
};
}
import javax.swing.*;
import javax.swing.event.*;
class QQQ extends JFrame
{
JDesktopPane desk = new JDesktopPane();
JInternalFrame if1 = new JInternalFrame();
JButton bt1 = new JButton("button1");
JButton bt2 = new JButton("button2");
QQQ()
{
setContentPane(desk);
desk.add(if1);
JPanel p = new JPanel();
p.add(bt1);
p.add(bt2);
if1.getContentPane().add(p);
if1.addInternalFrameListener(new MyListener());
if1.reshape(10,10,100,100);
if1.setVisible(true);
setBounds(100,100,400,400);
setVisible(true);
}
public static void main(String[] args)
{
new QQQ();
}
class MyListener extends InternalFrameAdapter
{
public void internalFrameActivated(InternalFrameEvent e )
{
bt1.requestFocus();
}
};
}