Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
541 views
in Technique[技术] by (71.8m points)

swing - suggestions for declarative GUI programming in Java

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: 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?

  2. 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.

  3. 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.

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

A simple example from the manual [PDF]:

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

Alternatively:

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

Or even:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...