简体   繁体   English

Swing中的属性列表GUI组件

[英]Property list GUI component in Swing

How do you make a "property list" component in Swing? 你如何在Swing中创建一个“属性列表”组件? I mean the kind as in this or this image. 我的意思是这个这个图像的那种。 Is it just a customized JTable component, or a custom component altogether? 它只是一个定制的JTable组件,还是一个自定义组件?

if you don't want to code it yourself, JideSoft has a component called PropertyPane. 如果您不想自己编写代码,JideSoft有一个名为PropertyPane的组件。 It's part of their Jide Grids package that costs $299.99. 这是他们的Jide Grids套餐的一部分,售价299.99美元。

I have't used that specific component, but I can say from experience that their components are very well polished and executed. 我没有使用过那个特定的组件,但我可以从经验中说,他们的组件经过精心打磨和执行。

A webstart demo of all their components 所有组件的webstart演示

hth 心连心

Koen 公园

Here is a basic example you might be able to further customize for your use: 以下是您可以进一步自定义以供使用的基本示例:

import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

public class TablePropertyEditor extends JFrame
{
    public TablePropertyEditor()
    {
        String[] columnNames = {"Type", "Value"};
        Object[][] data =
        {
            {"String", "I'm a string"},
            {"Date", new Date()},
            {"Integer", new Integer(123)},
            {"Double", new Double(123.45)},
            {"Boolean", Boolean.TRUE}
        };

        JTable table = new JTable(data, columnNames)
        {
            private Class editingClass;

            public TableCellRenderer getCellRenderer(int row, int column)
            {
                editingClass = null;
                int modelColumn = convertColumnIndexToModel(column);

                if (modelColumn == 1)
                {
                    Class rowClass = getModel().getValueAt(row, modelColumn).getClass();
                    return getDefaultRenderer( rowClass );
                }
                else
                    return super.getCellRenderer(row, column);
            }

            public TableCellEditor getCellEditor(int row, int column)
            {
                editingClass = null;
                int modelColumn = convertColumnIndexToModel(column);

                if (modelColumn == 1)
                {
                    editingClass = getModel().getValueAt(row, modelColumn).getClass();
                    return getDefaultEditor( editingClass );
                }
                else
                    return super.getCellEditor(row, column);
            }

            //  This method is also invoked by the editor when the value in the editor
            //  component is saved in the TableModel. The class was saved when the
            //  editor was invoked so the proper class can be created.

            public Class getColumnClass(int column)
            {
                return editingClass != null ? editingClass : super.getColumnClass(column);
            }
        };

        table.setPreferredScrollableViewportSize(table.getPreferredSize());
        JScrollPane scrollPane = new JScrollPane( table );
        getContentPane().add( scrollPane );
    }

    public static void main(String[] args)
    {
        TablePropertyEditor frame = new TablePropertyEditor();
        frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
        frame.pack();
        frame.setLocationRelativeTo( null );
        frame.setVisible(true);
    }
}

It is definately a table based component, but creation of it is not trivial. 它绝对是一个基于表的组件,但创建它并非易事。 I suggest you use already existing one. 我建议你使用现有的。 Here is a link to a free and very good one: http://www.l2fprod.com/common/ 这是一个免费且非常好的链接: http//www.l2fprod.com/common/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM