本文介绍了对 Java 中声明式 GUI 编程的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道对于 Java 中的声明式 GUI 编程是否有任何建议.(我讨厌基于可视化的 GUI 创建者/编辑器软件,但我对手动实例化 JPanels 和 Boxes 以及 JLabels 和 JLists 等有点厌倦了)

I wonder if there are any suggestions for declarative GUI programming in Java. (I abhor visual-based GUI creator/editor software, but am getting a little tired of manually instantiating JPanels and Boxes and JLabels and JLists etc.)

这是我的总体问题,但对于我正在考虑采取的方法,我有两个具体问题:

That's my overall question, but I have two specific questions for approaches I'm thinking of taking:

  1. JavaFX:JavaFX 中是否有一个真实的 GUI 显示示例(例如,不是圆形和矩形,而是列表框、按钮和标签等),它可以与 Java 源文件进行交互,该文件可以访问和更新各种元素?

  1. JavaFX: is there an example somewhere of a realistic GUI display (e.g. not circles and rectangles, but listboxes and buttons and labels and the like) in JavaFX, which can interface with a Java sourcefile that accesses and updates various elements?

Plain Old Swing 可以解析 XUL-ish XML:有没有人为 XML 发明了一种声明性语法(如 XUL)以便与 Java Swing 一起使用?我想创建一些基于 STaX 的代码并不难,它读取 XML 文件,实例化 Swing 元素的层次结构,并通过某种对象模型使层次结构可访问.但我宁愿使用众所周知的、有记录的和经过测试的东西,而不是自己尝试发明这样的东西.

Plain Old Swing with something to parse XUL-ish XML: has anyone invented a declarative syntax (like XUL) for XML for use with Java Swing? I suppose it wouldn't be hard to do, to create some code based on STaX which reads an XML file, instantiates a hierarchy of Swing elements, and makes the hierarchy accessible through some kind of object model. But I'd rather use something that's well-known and documented and tested than to try to invent such a thing myself.

JGoodies Forms -- 不完全是声明性的,但有点接近 &JGoodies Binding 祝我好运.但是他们的表单布局语法似乎有点神秘.

JGoodies Forms -- not exactly declarative, but kinda close & I've had good luck with JGoodies Binding. But their syntax for Form Layout seems kinda cryptic.

这里有很多很棒的答案!(& 我在上面添加了 #3)如果听到你们中的任何人在实际应用程序中使用这些框架之一的任何经验,我会特别感激.

edit: lots of great answers here! (& I added #3 above) I'd be especially grateful for hearing any experiences any of you have had with using one of these frameworks for real-world applications.

附言我确实尝试了一些谷歌搜索(java gui declarative"),只是不太知道要寻找什么.

p.s. I did try a few google searches ("java gui declarative"), just didn't quite know what to look for.

推荐答案

你可以看看 javabuilders;它使用 YAML 来构建 Swing UI.

You might have a look at javabuilders; it uses YAML to build Swing UIs.

手册 [PDF]:

JFrame:
    name: myFrame
    title: My Frame
    content:
        - JLabel:
            name: myLabel2
            text: My First Label
        - JLabel:
            name: myLabel2
            text: My Second Label

或者:

JFrame:
    name: myFrame
    title: My Frame
    content:
        - JLabel: {name: myLabel2, text: My First Label}
        - JLabel: {name: myLabel2, text: My Second Label}

甚至:

JFrame(name=myFrame,title=My Frame):
    - JLabel(name=myLabel2, text=My First Label)
    - JLabel(name=myLabel2, text=My Second Label)

这篇关于对 Java 中声明式 GUI 编程的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 12:01