0

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.

Can you provide me some examples or which classes should I use to resolve the problem ?

Thanks @trashgod, this is gonna really help me. 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? 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);
  • 1
    Did you look at the [docs](http://docs.oracle.com/javase/tutorial/uiswing/) ? – Salah Eddine Taouririt May 06 '13 at 23:56
  • Yeah, but i didn't find what i was looking for. I'm new about graphics and all that i have found was jSplitpane, jTextArea and jTextPane. But it seems to me, that each one is missing one of my requirements. – Claudio Saponi May 07 '13 at 00:10
  • 2
    Start with [Creating a UI with Swing](http://docs.oracle.com/javase/tutorial/uiswing/) and have a look at [How to use Tables](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html) and [How to use lists](http://docs.oracle.com/javase/tutorial/uiswing/components/list.html) – MadProgrammer May 07 '13 at 00:12

1 Answers1

3

You can use a StyledDocument in a JTextPane, illustrated here, usng any of a variety of layouts.

image

Addendum: I'd want…half the frame's width side-by-side that resize themselves when the frame expands…I tried setSize() and setPreferredSize().

Don't use setPreferredSize(). Do add your two text panes to a GridLayout(1, 0), which means "one row & some arbitrary number of columns". After pack(), use setExtendedState() as shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    If you need additional guidance, please edit your question to include an [sscce](http://sscce.org/) that exhibits the problem you encountered and comment here. – trashgod May 07 '13 at 11:52
  • Last question (i hope). Once i add these formatted strings, i need also to remove some of them from JTextPane. Do i need JTextPane or StyledDocument ? Isn't there something easier to add/remove styled strings from a text area? Thanks a lot, you're a big help. – Claudio Saponi May 07 '13 at 14:23
  • `StyledDocument` is the _model_; `JTextPane` is a _view_ of that _model_. Many components [accept limited HTML](http://docs.oracle.com/javase/tutorial/uiswing/components/html.html). – trashgod May 07 '13 at 18:35