-1

I am having issues with my java application and I can't find a suitable reply. In summary a right click triggered default pop up menu changes my chart's background color behind the pop up. You can find images below. I am happy to keep the default popup without the "buggy" behaviour or develop my own if required.

A click of a button starts a stream of data and adds a chart to a JInternalFrame component:

https://i.stack.imgur.com/CqQFx.png

If I right click on the image a default pop up comes up:

https://i.stack.imgur.com/j4GuT.png

If I then click away the rectangle area covered by the popup will overlay the chart like this:

https://i.stack.imgur.com/pGaV2.png

        TimeseriesMonitorModel model = new DefaultTweetMonitorModel();

        jif.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        try {

            jif.setContentPane(new TweetSeriesChartPane(model, TweetMonitor.keywords, tkc));
            jif.setSize(jif.getWidth(), jif.getHeight());
        } catch (InterruptedException ex) {
            Logger.getLogger(TweetMonitor.class.getName()).log(Level.SEVERE, null, ex);
        }

        jif.setVisible(true); 

where jif is the Jinternalframe and

   public TweetSeriesChartPane(TimeseriesMonitorModel model, String[] seriesNames, TweetKeywordCount tkc) throws InterruptedException {

    this.seriesNames = seriesNames;
    this.tkc = tkc;        
    this.model = model;


    XYChartTimeseries myRealTimeChart = new XYChartTimeseries();
    chart = myRealTimeChart.getChartWithTitle();

    List[] tweetData = model.getFrequencyCount(new AtomicIntegerArray(seriesNames.length)); // we are starting from 0

    int i = 0;
    for (String keyword : seriesNames) {
        List<Integer> yData = (List<Integer>) tweetData[1].get(i);
        chart.addSeries(keyword, tweetData[0], yData); // adding first value
        i++;
    }

    setLayout(new BorderLayout());

    XChartPanel<XYChart> chartPane = new XChartPanel<>(chart);
    add(chartPane);

    UpdateWorker worker = new UpdateWorker(this, seriesNames, this.tkc);
    worker.execute();

}
  • 2
    Guess #1 - You're violating the custom painting rules some how; Guess #2 - You've tried to use a alpha based color on a component which is opaque; Guess #3 - You're doing something wrong, but since you've provided zero context to how the problem might be replicated, it's impossible to know what you're doing wrong. [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – MadProgrammer Dec 05 '18 at 21:31
  • Hi Madprogrammer, I've tried looking into your Guess #2 but changing the opaque or the color wasn't changing the behaviour. What I posted above doesn't happen when I launch the application (aka… right click does not perform event). However, the start stream will add to the Jinternalframe a ChartPanel (which updates every x minutes). When this is added it allows me to right click on the chart – Roberto Sangineto Dec 05 '18 at 22:10
  • 2
    Read the link of my last comment - it's impossible to provide you any kind of support without it – MadProgrammer Dec 05 '18 at 22:12
  • I've added some code. Hope it helps – Roberto Sangineto Dec 05 '18 at 22:19
  • 1
    *"I've added some code."* It's a pity you did not read, or at least understand, the link offered by @MadProgrammer. Which is it? – Andrew Thompson Dec 06 '18 at 02:10

1 Answers1

0

I've managed to temporary solve the above.

I've checked specifically this line of code

XChartPanel<XYChart> chartPane = new XChartPanel<>(chart);

which extends Chart and Jpanel. The code is from the knowm-chart dependency https://github.com/knowm/XChart/blob/develop/xchart/src/main/java/org/knowm/xchart/XChartPanel.java)

Apparently it adds a listener and the customized PopUpMenu. After reviewing it, it looks like it didn't do any repainting when the mouse was clicked outside the PopUpMenu area. So I created a new class and tried to customise it. However, the repaint was flickering the screen and I couldn't get it to work only in the PopUpMenu area.

I ended up disabling the .addMouseListener call so now I don't get any popUpMenu. I sad compromise, but oh well.

BTW: Thanks to both, regardless of the last unneeded comment which didn't add any value.

I did read the link and I though I provided enough information.

In any case, posting to code helped me troubleshoot it