简体   繁体   English

控制jtable的AutoFilterTableHeader的弹出(下拉)菜单大小

[英]Controlling pop-up (dropdown) menu size of a AutoFilterTableHeader for a jtable

How do I control the size of the auto filter pop-up menu for a jtable header. 如何控制jtable标头的自动筛选器弹出菜单的大小。 I have some long text as the cell input and the pop-up menu spans across monitors? 单元格输入和弹出菜单跨监视器时,我有一些长文本?

在此处输入图片说明

columnName =[{'Date'},{'RSS'},{'Title'},{'Description'}];
    DTM = javaObjectEDT(com.jidesoft.grid.DefaultTableModel(data,columnName));
    jtable = javaObjectEDT(com.jidesoft.grid.SortableTable(DTM));
    theader = javaObjectEDT(com.jidesoft.grid.AutoFilterTableHeader(jtable));
    theader.setAutoFilterEnabled(true)
    % theader.setShowFilterName(true)
    theader.setShowFilterIcon(true)
    theader.setAllowMultipleValues(true)
    jtable.setTableHeader(theader)

JIDE grid developers guide doesn't really touch this issue but it is clear that one can extend AutoFilterTableHeader to control the width of the pop-up panel which indeed is a jpanel. JIDE网格开发人员指南并没有真正解决这个问题,但是很明显,可以扩展AutoFilterTableHeader来控制确实是jpanel的弹出面板的宽度。 Instead of attaching listener to the popup and then changing the width of the panel; 而不是将侦听器附加到弹出窗口,然后更改面板的宽度; I override PopupPanel (including its super classes) and set width equal to width of the current column and it works well. 我重写PopupPanel(包括其超类),并将width设置为等于当前列的宽度,并且效果很好。

import com.jidesoft.combobox.PopupPanel;
import com.jidesoft.grid.AutoFilterBox;
import com.jidesoft.grid.AutoFilterTableHeader;
import com.jidesoft.grid.AutoFilterTableHeaderEditor;

import javax.swing.*;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableModel;
import java.awt.*;

public class AutoFilterPopSize extends AutoFilterTableHeader
{
    public AutoFilterPopSize(JTable table)
    {
        super(table);
    }

    @Override
    protected TableCellEditor createDefaultEditor()
    {
        if (isAutoFilterEnabled())
        {
            return new AutoFilterTableHeaderEditor()
            {
                @Override
                protected AutoFilterBox createAutoFilterBox()
                {
                    return new AutoFilterBox()
                    {
                        @Override
                        protected PopupPanel createPopupPanel(TableModel tableModel, int columnIndex, Object[] possibleValues)
                        {
                            PopupPanel panel = super.createPopupPanel(tableModel, columnIndex, possibleValues);
                            panel.setStretchToFit(false);
                            int wdth = columnModel.getColumn(columnIndex).getWidth();
                            panel.setPreferredSize(new Dimension(wdth, 400));
                            return panel;
                        }
                    };
                }
            };
        }
        else {
            return null;
        }
    }
}

But still remains one unresolved issue; 但仍然是一个未解决的问题。 when jide's custom filter is selected and a condition is set, the dialog box size is still spanning across the monitors. 当选择了jide的自定义过滤器并设置了条件时,对话框的大小仍然跨越监视器。 Any ideas on how to fix that now? 关于现在如何解决的任何想法? Any direction you give would be helpful to a non programmer like me. 您提供的任何指导都会对像我这样的非程序员有所帮助。 Thank you. 谢谢。

Popup Width set properly 弹出宽度设置正确 https://i.stack.imgur.com/tIMIT.png

Custom Filter Dialog size still messed up 自定义过滤器对话框大小仍然混乱 在此处输入图片说明

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

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