suggestions for declarative GUI programming in Java

前端 未结 14 1109
有刺的猬
有刺的猬 2020-12-07 09:39

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 i

14条回答
  •  北海茫月
    2020-12-07 10:28

    If conciseness is important you might want to consider the double brace idiom:

    new JFrame("My Frame") {{
        setName("myFrame");
        add(new JLabel("My First Label") {{
             setName("myLabel2");
        }};
        add(new JLabel("My Second Label") {{
             setName("myLabel2");
        }};
    }}
    

    You then don't lose any of the power of a well known general purpose programming language (you know you are going to need it, and JellyTags suck). All you need is the one little extra idiom.

    It's not used very much, because actually people pissing around with XML weren't solving real pain points.

    In general you can use builder layers to abstract repeated code. GUI code doesn't have to be badly written, it's just that almost all of it is (including in text books).

提交回复
热议问题