0

I'm writing a Java program and I use JSplitPane to split between two JTextPanes.
The bottom JtextPane is in JTabbedPane.

public class test extends JFrame{

private JTextPane commandTextPane = new JTextPane();
private JPanel tokenPanel;
private JTextPane tokenTextPane = new JTextPane();

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                test window = new test();
                window.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
public test (){
    setBounds(100, 100, 900, 700);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    commandTextPane.setBounds(0, 0, 200, 300);
    commandTextPane.setPreferredSize(new Dimension(200, 300));

    //create ressultTabPane
    JTabbedPane resultTabPane = new JTabbedPane();
    tokenTabPanel();

    resultTabPane.addTab("Token", tokenPanel);

    JScrollPane topScroll = new JScrollPane(commandTextPane,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    TextLineNumber topLine = new TextLineNumber(commandTextPane);
    topScroll.setRowHeaderView(topLine);
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true,
            topScroll, resultTabPane);

    splitPane.setOneTouchExpandable(true);
    getContentPane().add(splitPane);
    setVisible(true);
}

public void tokenTabPanel() {
    tokenPanel = new JPanel();
    tokenTextPane.setBounds(0, 0, 200, 300);
    tokenTextPane.setPreferredSize(new Dimension(200,300));

    JScrollPane tokenScroll = new JScrollPane(tokenTextPane,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    TextLineNumber tokenLine = new TextLineNumber(tokenTextPane);
    tokenScroll.setRowHeaderView(tokenLine);

    tokenPanel.add(tokenScroll);
}

}

The problem is I can't set Bounds and PreferedSize of those JTextPanes. When I set them, the top JTextPane is not expect size and the bottom JTextPane is not in the top-left also its size.

image --> (http://upic.me/show/54858871)

Do you know how to fix them? Sorry for my English. Thanks in advance.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • I can't access your picture. – Sören Titze Mar 06 '15 at 10:54
  • Short answer, you don't. See [Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing?](http://stackoverflow.com/questions/7229226/should-i-avoid-the-use-of-setpreferredmaximumminimumsize-methods-in-java-swi) for a discussion on that subject. – MadProgrammer Mar 06 '15 at 10:54
  • Swing relies on the use of layout managers to position and size it's components. Take a closer look at [Laying Out Components Within a Container](http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html) for more details – MadProgrammer Mar 06 '15 at 10:55
  • 1
    Unless you're using styled text, you could use a `JTextArea` which would allow you to define the `rows` and `columns` you would optimally liked displayed which provides a hint to how best to layout/size the component – MadProgrammer Mar 06 '15 at 10:56

0 Answers0