如何在Matlab中自定义JIDE网格 [英] How to customise JIDE grids in Matlab

查看:151
本文介绍了如何在Matlab中自定义JIDE网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JIDE网格以uitable格式加载海量数据表.我使用JIDE网格的主要原因是要具有有效的过滤和排序功能.那里有可用的过滤器/分类器,可以与旧的uitable挂钩,并且更易于配置,但大多数按词法而不是数字进行分类.我相信这是由于Matlab的基础数据类造成的.

I am using JIDE grids for loading huge data tables in a uitable format. My main reason for using JIDE grid was to have a working filtering and sorting ability. There are filter/sorters available out there which can be hooked with old uitable and are easier to configure but most sort lexically rather than numerically. I believe that is due to Matlab's underlying data class.

到目前为止,当我加载接近500x35的混合数据类型时,JIDE的内置过滤效果很好,并且可加载的速度甚至比Matlab中旧版本的uitable更快.但是我还想配置一些其他东西,但在JIDE文档中没有找到相关内容.

So far, JIDEs inbuilt filtering is working well and uitable loads even faster than old version of uitable in Matlab when I load neary 500x35 of mixed data type. But there are a few other things that I would like to configure, to which I have found no referent in JIDE documentation.

1)有人知道如何在JIDE实现中添加行号列吗? (就像旧/新的uitable配置中的行号标头一样).我试图使用findobj和inspect(由Yair Altman开发)实用程序来找到它们并打开它们,但是它们似乎完全丢失了.或者我丢失了一些东西!

1) Does anyone knows how to add row number column in JIDE implementation? (just like row number header in old/new uitable configurations). I have tried to use findobj and inspect (by Yair Altman) utility to find them and switch them on but they seems to be completely missing.Or I am missing something!

2)当我们从列下拉列表中选择自定义过滤器"并选择是"或不等于"或大于"时,它会显示一个日期选择标签,那么我们如何删除此标签.如果那是不可能的或困难的,我该如何删除这些选项?

2) When we select 'custom filter' from the column dropdown and pick 'is' or 'doesn't equal' or 'is greater than' it shows a date selection tab, how can we remove this tab. If that is not possible or difficult, how can I remove these options?

3)最后,如何设置网格中显示的小数位数?

3) Lastly, How can I set the number of decimal places displayed in the grid?

用于重现问题的代码.

% calling old uitable for performance reasons
f1=figure;
[h_Old,containter] = uitable('v0','data',magic(5),'ColumnNames',{'A','B',...
    'C','D','E'},'Position',[5 5 500 400],'Parent',f1);
set(h_Old,'Units','normalized','Editable',false);

% Anotherway: JIDE grids even faster in setting up uitable with huge data
data=num2cell(magic(5));
jtable=com.jidesoft.grid.SortableTable(data,{'A','B','C','D','E'});
theader = com.jidesoft.grid.AutoFilterTableHeader(jtable);
theader.setAutoFilterEnabled(true)
theader.setShowFilterName(true)
theader.setShowFilterIcon(true)
jtable.setTableHeader(theader)
jscroll = javax.swing.JScrollPane(jtable);
f2=figure;
[h_old_2,container_2] = javacomponent(jscroll,[5,5,500,400],f2)
set(container_2,'Units','norm');

感谢您的时间和帮助.

推荐答案

为其他可能面临相同问题的人的利益进行解答.

Answering for the benefit of the other who might face the same problem.

1)JID​​E自动没有行标题.可以通过TableScrollPane完成,不幸的是,这要复杂得多.一个简单的解决方法是,通过对DefaultTableCellRenderer进行更改,使第一列作为行标题,并为其赋予行标题外观".下面的代码.我认为从长远来看,这很容易维护.

1) JIDE does not have a row header automatically. It can be done via TableScrollPane which is unfortunately a lot of more complicated. A simple workaround is to make first column as row header and giving it a 'Look and Feel' of a row header by making changes to DefaultTableCellRenderer. Code below. I guess this is easily maintainable in the long run.

% Making changes to DefaultTableCellRenderer
% Give first column a header look, Center data
cr0 = javax.swing.table.DefaultTableCellRenderer();
cr0.setHorizontalAlignment(0) % 0 for CENTER, 2 for LEFT and 4 for RIGHT
cr0.setBackground(java.awt.Color(15790320)); % grey backgroundt
jtable.getColumnModel.getColumn(0).setCellRenderer(cr0);
jtable.getColumnModel.getColumn(0).setResizable(false);
jtable.getColumnModel.getColumn(0).setMaxWidth(32);

2)这可以通过定义jtable列类来完成.仍在进行中.会尽快更新我的答案.

2) This can be done by defining jtable column class. Still work in progress. Will update my answer soon.

3)可以通过在Java中为DefautTableCellRenderer写一个简单的扩展名来设置小数位.对其进行编译,以获取一个类>在matlab中此类的javaaddpath>用您的TableCellRenderer替换DefaultTableCellRenderer.下面是一个示例Java类:

3) Decimal places can be set by writing a simple extension to DefautTableCellRenderer in Java. Compile this to get a class > javaaddpath to this class in matlab > replace DefaultTableCellRenderer with your TableCellRenderer. A sample Java Class is below:

import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.text.DecimalFormat;
public class CustomCellRenderer extends DefaultTableCellRenderer implements TableCellRenderer
{
    public Component getTableCellRendererComponent
            (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    {
        JComponent cell = (JComponent) super.getTableCellRendererComponent
                (table, value, isSelected, hasFocus, row, column);
        // set color
        cell.setBackground(new Color(0xC8C8C8));
        cell.setForeground(new Color(0xFFFFFF));

        //set Alignment
        ((JLabel)cell).setHorizontalAlignment(SwingConstants.CENTER);

        //set selection colors
        if (isSelected){
            cell.setBackground(new Color(0x3399FF));
            cell.setForeground(new Color(0x000000)); // AM
        }else{
            // set decimals
            DecimalFormat DecimalFormatter = new DecimalFormat("#.00");
            value = DecimalFormatter.format(value);
            return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        }
    return cell;
    }

}

将此类添加到Matlab中,并用这样的TableCellRenderer替换DefaultTableCellRenderer.

Add this class to Matlab and replace replace DefaultTableCellRenderer with your TableCellRenderer like this.

data = {8.252,1.528,6.2598; 3.258,5.548,7.698; 4.448,9.5454,2.5644}; 
cols = {'A','B','C'}
DTM=javax.swing.table.DefaultTableModel(data,cols);
jtable = com.jidesoft.grid.SortableTable();
jtable.setModel(DTM);
jscroll = javax.swing.JScrollPane(jtable);
[htable,container] = javacomponent(jscroll,[5,5,500,400]);
set(container,'Units','norm');
javaaddpath('\ExternalSources\JavaExtenstions\CustomCellRenderer');
cr=CustomCellRenderer();
for i=0:2, jtable.getColumnModel.getColumn(i).setCellRenderer(cr), end;
jtable.repaint;

希望这可以帮助其他面临相同问题的人.

Hope this help others facing the same issue.

这篇关于如何在Matlab中自定义JIDE网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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