单击按钮后更改JPanel [英] change JPanel after clicking on a button

查看:96
本文介绍了单击按钮后更改JPanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序构建简单的GUI.我有几个JPanels.我想根据单击JButton所执行的操作来显示它们.如何禁用一个JPanel并启用另一个JPanel?

I'm building simple GUI for my app. I have couple of JPanels. I want to display them depending on action that was performed by clicking on a JButton. How can I disable one JPanel and enable another one ?

详细信息.我有一个JFrame课,我正在这里开始创建gui.我有按钮和一些文字的地方.单击其中一个按钮应更改此JFrame中的视图

Couple of details. I have a class with JFrame where I'm building starting gui. Where I have buttons and some text. Clicking on one of the buttons should change the view in this JFrame

我的按钮定义

    JButton btnStart = new JButton("Start");
    btnStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

        }
    });
    btnStart.setBounds(10, 11, 110, 23);
    contentPane.add(btnStart);

//编辑

我发现了问题.按钮是静态方法

I've found the problem. buttons were in static method

推荐答案

简单为:

jframe.setContentPane(your_new_panel);
jframe.invalidate();
jframe.validate();

这篇关于单击按钮后更改JPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆