[英]How to split a frame into views with multiple lines
I'm doing this program with NetBeans
and I need: a Frame
with a split view, fitting the frame's width, each view has multiple lines, where I add/remove
strings, these strings can have a particular font and colors. 我在做此程序
NetBeans
和我需要:一个Frame
与拆分视图,配合框架的宽度,每个视图具有多行,其中,I add/remove
字符串,这些串可以具有一个特定的字体和颜色。
Can you provide me some examples or which classes should I use to resolve the problem ? 您可以提供一些示例,还是应该使用哪些类解决问题?
Thanks @trashgod, this is gonna really help me. 谢谢@trashgod,这将对我有很大帮助。 About the layouts, i've build in netbeans a jframe that it expands to the full resolution of the screen in use, and inside of it i'd want ,as you suggested to me, 2 JTextPane half the jframe's width side by side that resize themselves when the jframe expands...until now i tried setSize() and setPreferredSize() on each JTextPane, but so far nothing...any idea why isn't working?
关于布局,我在netbeans中构建了一个jframe,它可以扩展到使用中的屏幕的完整分辨率,并且在其中,我想要的是,正如您向我建议的那样,将2个JTextPane并排放置在jframe宽度的一半处,当jframe扩展时调整自身大小...直到现在我在每个JTextPane上尝试了setSize()和setPreferredSize(),但是到目前为止,什么都没有...为什么不起作用? here's my code
这是我的代码
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int)screenSize.getWidth();
int height = (int)screenSize.getHeight();
System.out.println(width +" x "+ height);
this.setSize(width,height);
Dimension dimTextArea1 = new Dimension((width/2),height);
Dimension dimTextArea2 = new Dimension((width/2),height);
jTextPane1.setPreferredSize(dimTextArea1);
jTextPane2.setPreferredSize(dimTextArea2);
You can use a StyledDocument
in a JTextPane
, illustrated here , usng any of a variety of layouts . 您可以使用
StyledDocument
一个JTextPane
,说明这里 ,USNG任何各种各样的布局 。
Addendum: I'd want…half the frame's width side-by-side that resize themselves when the frame expands…I tried setSize()
and setPreferredSize()
. 附录: 我想…将框架的宽度并排的一半减半,以便在框架扩展时自行调整大小…我尝试了
setSize()
和 setPreferredSize()
。
Don't use setPreferredSize()
. 不要使用
setPreferredSize()
。 Do add your two text panes to a GridLayout(1, 0)
, which means "one row & some arbitrary number of columns". 不要添加两个文本窗格的
GridLayout(1, 0)
这意味着“一行与列的一些任意数字”。 After pack()
, use setExtendedState()
as shown here . 后
pack()
使用setExtendedState()
如图所示这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.