Code Monkey home page Code Monkey logo

Comments (15)

eugener avatar eugener commented on May 23, 2024

I've updated the code according to the discussion on stackoverflow. Both, the old and the new variants work on my Mac. Please test and let me know.
Also, the best way to suggest a change is to simply send a pull request :)

from oxbow.

priyath avatar priyath commented on May 23, 2024

Hey thanks for the prompt response, The stackoverflow suggestion does not work. The ancestor window returned by menu.getTopLevelAncestor() is of the jtable. Attempts to drag and resize the popupmenu changes the dimensions of the entire jtable in my case. I still have not found a fix for this. A possible reason is addressed by MadProgrammer in my stackoverflow post.

This is for the old variant:

"A call to setPopupSize, calls showPopup, this will close the current popup (if one is visible) and recreate the window based on the new preferredSize of the popup. How the window is actually created is dependent on a number of system critieria. the MouseListeners remain intact, but, because the window is made visible, the mouse events are no longer been sent to it, but to the window beneath it, and, well, the whole thing explodes in flames. This is a bug that the author of SwingBits is going to have to address"

from oxbow.

priyath avatar priyath commented on May 23, 2024

This is the code that i'm using to test the swing bits filter. Would be interesting to know if it is possible for you to resize the jpopupmenu that appears on a column header right click.

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.ezware.oxbow.swingbits.table.filter.TableRowFilterSupport;

public class TableExample extends JFrame
{
    private JPanel topPanel;
    private JPanel btnPanel;

    public TableExample() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
    {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        //headers for the table
        String[] columns = new String[] {
            "Id", "Name", "Hourly Rate", "Part Time"
        };

        //actual data for the table in a 2d array
        Object[][] data = new Object[][] {
            {1, "John", 40.0, false },
            {2, "Rambo", 70.0, false },
            {3, "Zorro", 60.0, true },
        };

        topPanel = new JPanel();
        btnPanel = new JPanel();

        add(topPanel, BorderLayout.CENTER);
        add(btnPanel, BorderLayout.SOUTH);

       //create table with data
        JTable table = new JTable(data, columns);
        TableRowFilterSupport.forTable(table).searchable(true).apply();
        JButton button = new JButton();
         button.setText("save");
        //add the table to the frame
        topPanel.add(new JScrollPane(table));
        btnPanel.add(button);
        this.setTitle("Table Example");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       
        this.pack();
        this.setVisible(true);

        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae){

                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                table.getColumnModel().getColumn(0).setPreferredWidth(15);
                table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
            }

           });
    }

    public static void main(String[] args)
    {

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    new TableExample();
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (UnsupportedLookAndFeelException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
    }   
}

from oxbow.

eugener avatar eugener commented on May 23, 2024

Does the TableFilterTest example produces the same issue?

from oxbow.

priyath avatar priyath commented on May 23, 2024

Yes

from oxbow.

eugener avatar eugener commented on May 23, 2024

Which Java version are you running under? Under my 1.8.0_65 I see no issue at all anymore.

from oxbow.

eugener avatar eugener commented on May 23, 2024

Your example also works

from oxbow.

priyath avatar priyath commented on May 23, 2024

Well look at that! I was running java 1.8.0_25 (x64), updated to 1.8.0_66 (x64) and the issue is no longer there. Both the old and new variants work fine. Thank you for the quick responses and apologies for any inconveniences caused.

from oxbow.

eugener avatar eugener commented on May 23, 2024

Glad to hear that! Last commit actually makes popup resizing smoother, so thank you for making me look into the issue :)

from oxbow.

priyath avatar priyath commented on May 23, 2024

There is a problem with the latest commit, Re-sizing works fine if part of the popupmenu is outside of the table. But if the popupmenu is entirely inside the table, menu.getTopLevelAncestor() returns the window of the jtable which causes the table to resize and not the jpopupmenu.

from oxbow.

eugener avatar eugener commented on May 23, 2024

Just tested and don't see any issues :)

from oxbow.

priyath avatar priyath commented on May 23, 2024

Try maximizing the TableFilterTest table and re-sizing the jpopupmenu?

My code is as below.

...
if ( newDim.width >= minDim.width && newDim.height >= minDim.height) {
            //menu.setPopupSize(newDim);
            resizeMenu(newDim);
        }

    }

    private void resizeMenu(Dimension dim) {
        final Window window = (Window) menu.getTopLevelAncestor();
//        window.pack();
        window.setSize(dim);
//        window.validate();
    }

from oxbow.

priyath avatar priyath commented on May 23, 2024

The old variant menu.setPopupSize(newDim) works fine. Windows 8, jdk 1.8.0_66

from oxbow.

eugener avatar eugener commented on May 23, 2024

Pretty strange... both work well no my machine with OSX. Also old variant produces a flicker, but the new one does not

from oxbow.

eugener avatar eugener commented on May 23, 2024

Updated the code to use resizing method based on OS

from oxbow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.