在同一个JFrame中加入两个JInternalFrame A 和 B ,先加A再加B ,怎么让B在JFrame的最上层? 50
2个回答
展开全部
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class FrameTest extends JFrame implements ActionListener {
public static final int SIZE_1 = 500;
public static final int SIZE_2 = 400;
private JFrame myFrame;
private JButton button;
FrameTest(){
this.setTitle("我是母窗口");
this.setSize(SIZE_1, SIZE_1);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame = new JFrame("我是子窗口");
myFrame.setSize(SIZE_2, SIZE_2);
button = new JButton("显示子窗口");
button.addActionListener(this);
this.add(button);
this.setVisible(true);
}
public void getFramLocation(){
int newX = this.getX()+((SIZE_1 - SIZE_2)/2);
int newY = this.getY() +((SIZE_1 - SIZE_2)/2);
myFrame.setVisible(false);
myFrame.setLocation(newX, newY);
myFrame.setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new FrameTest();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
this.getFramLocation();
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class FrameTest extends JFrame implements ActionListener {
public static final int SIZE_1 = 500;
public static final int SIZE_2 = 400;
private JFrame myFrame;
private JButton button;
FrameTest(){
this.setTitle("我是母窗口");
this.setSize(SIZE_1, SIZE_1);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame = new JFrame("我是子窗口");
myFrame.setSize(SIZE_2, SIZE_2);
button = new JButton("显示子窗口");
button.addActionListener(this);
this.add(button);
this.setVisible(true);
}
public void getFramLocation(){
int newX = this.getX()+((SIZE_1 - SIZE_2)/2);
int newY = this.getY() +((SIZE_1 - SIZE_2)/2);
myFrame.setVisible(false);
myFrame.setLocation(newX, newY);
myFrame.setVisible(true);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new FrameTest();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
this.getFramLocation();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
JFrame frame=new JFrame("B");
frame.setAlwaysOnTop(true);
frame.setAlwaysOnTop(true);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询