Java中声明性GUI编程的建议 [英] suggestions for declarative GUI programming in Java

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

问题描述

我想知道在Java中是否有任何关于声明性GUI编程的建议。 (我厌恶基于视觉的GUI创建者/编辑器软件,但我对手工实例化JPanels和Boxes以及JLabel和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:有没有人发明过用于Java的声明语法(如XUL)用于Java Swing?我想,要创建一些基于STaX的代码来创建一些代码,实例化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表格 - 不完全是陈述性的,但有点接近&我和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.

PS我确实尝试了一些谷歌搜索(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编程的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆