repaint(),revalidate(),invalidate().如何使用它们? [英] repaint(), revalidate(), invalidate(). How to use them?

查看:369
本文介绍了repaint(),revalidate(),invalidate().如何使用它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对表格的显示有疑问.我的表最初有行.但是下次如果我执行某些操作,我的表列表将为空.因此,当我将该模型添加到表中时,该表为空.它是empty,但显示屏在表区域显示白色.

I have problem with display of table. My table initially has rows. But next time if I do some operation my table list becomes empty. So when I add that model to the table the table is empty. It is empty but the display is showing white colour in table area.

最初,该表如下图所示.

Initially the table looks like below figure.

然后我需要调用一些操作,如果该操作返回一个空列表,那么我正在创建一个新的 带有该列表的Jtable并将其放置在面板上.但它看起来像以下内容.

Then I need to call some action and if that action returns an empty list then I am creating a new Jtable with that list and placing it on the panel. But it is looking like the following.

以下是我正在尝试的方法,

Following is the approach which I am follwoing to do this,

pnlRight.removeAll();
//pnlRight.invalidate();
// pnlRight.revalidate();
// pnlRight.repaint();
pnlRight.add(new JScrollPane(table), BorderLayout.CENTER);
pnlRight.invalidate();
pnlRight.validate();
pnlRight.repaint();

在删除我后,我已经阅读了 @kdgregory 上的一篇文章.应该调用上面的方法.这种奇怪的事情正在发生.如果我只调用repaint(),则即使面板上也没有列名(理想情况下,这种情况下不应发生.)请解释一下这是什么问题.

I have read one of the post on this @kdgregory, after removing I should call the above methods. this weird thing is happening. If I call only repaint() then even the column names are missing from the panel (Ideally this should not happen in this case.) Please explain what is the problem with this.

推荐答案

  • 不是,我认为没有(逻辑)原因,要删除JTable(带有JScrollPane)并放置另一个JTable

    • not I think there isn't (logical) reason for that, to remove a JTable (with JScrollPane) and put there another JTable

      创建JTable并将所有数据存储到XxxTableModel

      create JTable and to store all data to XxxTableModel,

      重置XxxTableModel,然后以不同的结构加载另一个数据

      reset XxxTableModel and then to load another data in different structure

      使用CardLayout在视图之间进行切换

      use CardLayout for switching betweens views

      编辑

      • 以下代码

      pnlRight.revalidate();

      pnlRight.revalidate();

      pnlRight.repaint();

      pnlRight.repaint();

      没有引起任何问题,此代码中没有问题....

      there no caused any issue, problem isn't in this code....

      这篇关于repaint(),revalidate(),invalidate().如何使用它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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