开发者

Explanation for the java code?

开发者 https://www.devze.com 2023-03-28 04:32 出处:网络
What does this code mean: table = new开发者_如何学编程 JTable(){ public boolean isCellEditable(int arg0, int arg1) {

What does this code mean:

table = new开发者_如何学编程 JTable(){
        public boolean isCellEditable(int arg0, int arg1) {
            return true;
        }
    };


It's an anonymous class, which in this case has provided an implementation for JTable's isCellEditable method that always returns true.


Think of it as:

class MyJTable extends JTable
{
    public boolean isCellEditable(int arg0, int arg1) {
        return true;
    }
}
table = new MyJTable;


Whatever arguments you pass to isCellEditable of this instance of JTable, it will always return true. This is not the default behavior in JTable, so you're overriding this behavior of your instance.

(If you meant "why would anyone do that", it should get you a JTable in which every cell is editable)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号