简体   繁体   中英

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. 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. 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.

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. 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 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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