我目前正在使用Java Swing构建GUI。
我当前的代码产生了这个。
产品列表的JTextArea使GUI看上去很尴尬,我如何使JTextArea看起来像这样,它似乎有多余的一行:“>
我正在使用的GroupLayout代码是:
gr.setVerticalGroup(gr.createSequentialGroup()
.addGroup(gr.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(productName).addComponent(productText).addComponent(productList))
.addGroup(gr.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(amount).addComponent(amountText).addComponent(prodScroll))
.addGroup(gr.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(description).addComponent(desScroll))
.addGroup(gr.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(addButton).addComponent(remButton)));
gr.setHorizontalGroup(gr.createSequentialGroup()
.addGroup(gr.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(productName).addComponent(amount).addComponent(description).addComponent(addButton))
.addGroup(gr.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(productText).addComponent(amountText).addComponent(desScroll).addComponent(remButton))
.addGroup(gr.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(productList).addComponent(prodScroll)));
我目前正在使用Java Swing构建GUI。我当前的代码产生了这个。产品列表的JTextArea使GUI看起来很笨拙,如何使JTextArea看起来像这样,似乎在...
我认为少数人会选择使用GridBagLayout。但是,我不喜欢它(与GroupLayout
一起使用),因为它“很难使用”。我使用嵌套面板代替各种Layout Managers。仅使用BorderLayout
和GridLayout
即可实现以下示例,该示例完全可调整大小,重点是“交互”组件(我的意思是,没有理由调整文本常量JLabel
的大小,对吗? )