私は説明のために考えを単純化しました:なぜボタングラフィックは最新のJavaFXページにのみ表示されますか?重複したコントローラは互いに独立していないのですか?
私はMDIアプリケーションを持っています。ボタンがあります。そのボタンを押すと、そのMDIアプリケーション内に新しいウィンドウが開きます。ボタンをもう一度押すと、そのウィンドウの別の複製が開きます。ウィンドウにはボタンがあり、ボタンにはグラフィックス(SVG)があります。グラフィックスは正しく表示されますが、新しいウィンドウを開くと、グラフィックスは新しいウィンドウに表示されなくなり、最近開いたウィンドウにのみ表示されます。
これは懸念事項ではありませんが、同じ種類のさまざまなWindowsのすべての機能で問題になると思います。なぜこれが起こったのですか?ところで
:ライブラリはJFoenixとJFXtras
/* this will be called when the button is pressed to open a new window. mdiCenter is the anchor pane the windows are displayed on */
public void addWindow() throws IOException
{
try
{
BorderPane pane = FXMLLoader.load(getClass().getResource("MyPage.fxml"));
pane.setMinSize(400, 300);
Window window = new Window();
window.getContentPane().getChildren().add(pane);
mdiCenter.getChildren().add(window);
}
catch (IOException e)
{
e.printStackTrace();
}
}
/* this method is called when MyPage is initialized */
private void setButtonSvgs()
{
double size = 20;
String style = "-fx-background-color: white;";
button1.setGraphic(Util.getGlyph("SVGname", size, style));
button2.setGraphic(Util.getGlyph("SVGname", size, style));
button3.setGraphic(Util.getGlyph("SVGname", size, style));
button4.setGraphic(Util.getGlyph("SVGname", size, style));
}
/* the following are in the Util class. this is the method that's called in the method above^*/
private static final List<SVGGlyph> glyphs = SVGGlyphLoader.getAllGlyphsIDs().stream().map(item -> SVGGlyphLoader.getIcoMoonGlyph(item)).collect(Collectors.toList());
public static SVGGlyph getGlyph(String name, double size, String style)
{
for (SVGGlyph glyph : glyphs)
{
if (glyph.getName().equals(name))
{
glyph.setSize(size, size);
glyph.setStyle(style);
return glyph;
}
}
return null;
}
/* the SVG glyph list is initialized in the main application but I'm not sure that's relevant. */
は助けてくださいます!なぜこれが起こっているのか分かりません! FXMLがロードされるたびに、新しいコントローラをインスタンス化して他のコントローラと独立してはいけませんか?
静的メソッドを呼び出すので、新しいコントローラはこれまでに作成されませんyタイム。これは、Javadocが明確に主張していないものです... '非静的' load()メソッドを使用するたびに、新しいコントローラを作成したい場合。実際には私は8つのload()メソッドから2最初の静的ではないと思います.FXMLLoaderクラスを逆コンパイルすることでチェックできます。あなたがそれをキャッチしていない場合、私は答えを追加します;) – GOXR3PLUS