0

Updated to provided minimal reproducible example I have a program to takes in xml data, moves it into a arraylist and then displayed using JavaFX/FXML file. It works, but my right menu isn't as it used to be. It only shows "Export As" (zoom reset etc isn't there anymore), with a submenu, which doesn't display until mouseover. I have PNG, JPEG, PDF, SVG showing up, and they do work but I would like to add more features to the export. I've not been able to find clear resources to solve my problem.

Thanks

my Main:

import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;


public class Main extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    public void start(Stage primaryStage) throws Exception {

        Parent root = FXMLLoader.load(getClass().getResource("/ExportPDF.fxml"));
        primaryStage.setTitle("Bare Export PDF");
        primaryStage.setScene(new Scene(root, 1920, 1080));
        primaryStage.sizeToScene();
        System.out.println("javafx.runtime.version: " + System.getProperties().get("javafx.runtime.version"));
        primaryStage.show();
        primaryStage.setOnCloseRequest(e -> Platform.exit());
    }
}

My FXML.

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import org.jfree.chart.fx.ChartViewer?>

<AnchorPane xmlns="http://javafx.com/javafx"  xmlns:fx="http://javafx.com/fxml"  fx:controller="Controller"
            prefHeight="1000.0" prefWidth="1900.0">

    <Button fx:id="SubmitBtn"  layoutX="10.0" layoutY="10.0" onAction="#submitButtonClicked" prefHeight="30.0" prefWidth="125.0"  text="Submit" textFill="BLACK">
        </Button>


<ChartViewer fx:id="chartViewer" layoutY="50.0" layoutX="50.0" prefWidth="500" prefHeight="500" disable="true"/>


</AnchorPane>

My Controller

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import org.jfree.chart.fx.ChartViewer;

public class Controller {

    @FXML
    ChartViewer chartViewer;
    @FXML
    Button SubmitBtn = new Button("Submit");

    public void submitButtonClicked() {
    chartViewer.setDisable(false);
    new bathChart("Number of Tracks", "Months", "Tracks", chartViewer);
    }
}

My Method to call the chart once button is clicked

import org.jfree.chart.*;
import org.jfree.chart.fx.ChartViewer;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.StandardBarPainter;
import org.jfree.data.category.DefaultCategoryDataset;

import java.awt.*;
import java.util.ArrayList;

class bathChart {
    bathChart(String title, String catAxisLabel, String valAxisLabel, ChartViewer chartViewer) {

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(7445, "JFreeSVG", "Warm-up");
        dataset.addValue(24448, "Batik", "Warm-up");
        dataset.addValue(4297, "JFreeSVG", "Test");
        dataset.addValue(21022, "Batik", "Test");



        //Create the chart
        JFreeChart chart = ChartFactory.createBarChart(
                title, catAxisLabel, valAxisLabel, dataset,
                PlotOrientation.VERTICAL, true, true, false);

        String fontName = "Verdana";
        StandardChartTheme theme = (StandardChartTheme)org.jfree.chart.StandardChartTheme.createJFreeTheme();
        theme.setTitlePaint(Color.white);
        theme.setExtraLargeFont(new Font(fontName,Font.PLAIN, 18)); //title
        theme.setLargeFont(new Font(fontName,Font.BOLD, 15)); //axis-title
        theme.setRegularFont(new Font(fontName,Font.PLAIN, 11));
        theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
        theme.setPlotBackgroundPaint(Color.decode("#2b496f"));
        theme.setChartBackgroundPaint(Color.decode("#004872"));
        theme.setGridBandPaint(Color.red);
        theme.setBarPainter(new StandardBarPainter());
        theme.setAxisLabelPaint(Color.white);
        theme.apply(chart);
        chart.getCategoryPlot().setOutlineVisible(false);
        chart.getCategoryPlot().getRangeAxis().setAxisLineVisible(true);
        chart.getCategoryPlot().getRangeAxis().setTickMarksVisible(true);
        chart.getCategoryPlot().setRangeGridlineStroke(new BasicStroke());
        chart.getCategoryPlot().getRangeAxis().setTickLabelPaint(Color.white);
        chart.getCategoryPlot().getDomainAxis().setTickLabelPaint(Color.white);
        chart.setTextAntiAlias(true);
        chart.setAntiAlias(true);
        chart.getCategoryPlot().getRenderer().setSeriesPaint(0, Color.decode("#4572a7"));

        chartViewer.setChart(chart);
    }
}
rvz
  • 43
  • 6
  • [mcve] please .. – kleopatra Mar 17 '20 at 22:31
  • ``` ChartPanel chartPanel = new ChartPanel(chart,false,true,true,true,true); ``` I believe I should be adding this, but when I do it says chartPanel isn't being used, so something else should be calling it. Just haven't figured out what. – rvz Mar 19 '20 at 16:20
  • I added: JFrame frame = new JFrame(); chartPanel.setPreferredSize(new java.awt.Dimension(700, 470)); frame.getContentPane().add(chartPanel); frame.setVisible(true); Which gives me back my Right click menu but it pops up a new window, which isn't what I want. – rvz Mar 19 '20 at 21:29
  • The current version of [`createContextMenu()`](https://github.com/jfree/jfreechart-fx/blob/8ac05178c9b62cd5d7f093413688b81c918d6668/src/main/java/org/jfree/chart/fx/ChartViewer.java#L220) appears to support a limited subset of the Swing functionality. – trashgod Aug 11 '21 at 16:29

0 Answers0