Обновлен до предоставленного минимального воспроизводимого примера. У меня есть программа, которая принимает xml данные, перемещает их в массив и затем отображает их в файле JavaFX / F XML. Это работает, но мое правильное меню не так, как раньше. Он показывает только «Экспортировать как» (сброс масштаба и c больше не существует) с подменю, которое не отображается до наведения мыши. У меня есть PNG, JPEG, PDF, SVG, и они работают, но я хотел бы добавить больше возможностей для экспорта. Я не смог найти четких ресурсов для решения моей проблемы.
Спасибо
Мой главный:
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());
}
}
Мой F XML.
<?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>
Мой контроллер
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);
}
}
Мой метод вызова графика после нажатия кнопки
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);
}
}