0

I have JtabbedPane where every tab has a JtextPane wrapped inside a JScrollPane. The Vertical scroll bar is showing up when necessary, but the horizontal isn't, and instead of making a horizontal bar it cuts the text and continues it in next line, which is not a point. I have tried to resize the tab size and declaring the size of the scrollpane larger than tab's, but the result the same.

tabs = new TabbedPane();
tabs.setBounds(0, 0, windowWidth - 70, windowHight - 105);

for (Responses orgData: GUI.getOriginalRequest().getArrayOfResponses())
    {
        sc = StyleContext.getDefaultStyleContext();
        style = sc.addStyle("ConstantWidth", null);
        str = formatter.format((formatter.unformat(orgData.getXMLData())));
        ksd = new KeywordStyledDocument(style, sc, s);
        ksd.insertString(0, str, style);
        ksd.refreshDocument();
        pane = new JTextPane(ksd);
        pane.setFont(new Font("Courier New", Font.PLAIN, 12));

        panel = new JScrollPane(pane);
        panel.getHorizontalScrollBar().addAdjustmentListener(null);
        panel.setPreferredSize(new Dimension(windowWidth - 170, windowHight - 135));
        orgData.setXMLData(formatter.unformat(str));
        listener.addKeyAdapter(pane);
        tabs.addTab(orgData.getSystemName() + " (Original Request)", panel);
    }

What am I missing here?

Thank you.

Update:

After implementing the LineWrape by extending the JTextPane and adding pane.setLineWrap(false) that was sugested by Thanasis, the problem was resolved and the textPane which had a text that exceeded the bounds of the field, was wrapped and had a horizontal scroll bar, but textPane which text was less than the bounds of textPane was wrapped to the last character, and thus, the field became less than a space that is allocated to it, and it looks like panel split to 2 parts, textPane and panel.

How do I resolve this? Please suggest.

TextPane ends at the last character image

Marat
  • 21
  • 1
  • 4
  • I think this can help you: http://stackoverflow.com/a/2452758/7053344 – Thanasis1101 Feb 12 '17 at 13:48
  • It didn't. I have put the ScrollPane constants as suggested, but, the setAutoResizeMode did not, because I don't use JTable, and I have not found such option for JtabbedPane. – Marat Feb 12 '17 at 13:58
  • The problem is with the JTextPane, not the JTabbedPane. See the suggestions here: http://stackoverflow.com/questions/20713631/how-to-make-the-horizontal-scroll-bar-appear-in-a-jscrollpane-that-contains-a-jt – Thanasis1101 Feb 12 '17 at 14:06
  • Thank you that helped, but now I have other problem. In texts that their longest line is less than the textPane width, it wraps it around the texts, and result is that from the last letter to the end of the panel is blank panel and not a JtextPane. Is there a way to get the width of the textPane after it's wrap? setMinimumSize does not work. – Marat Feb 12 '17 at 14:47
  • Could you upload a picture of the result? – Thanasis1101 Feb 12 '17 at 15:13
  • [This link](http://java-sl.com/wrap.html) will have information that is useful to you. You're not restricting the size of your JTextPane in any way are you, such as by setting its bounds, size or preferred size? – Hovercraft Full Of Eels Feb 12 '17 at 15:46
  • 1
    I see lots of setBounds(...) and setPreferredSize(...) logic which generally indicates problems. The layout manager is responsible for setting the size and location of components. If you are not using a layout manager properly, then scrolling won't work properly either. `but now I have other problem` - post a proper [mcve] that demonstrates your problem. – camickr Feb 12 '17 at 18:51

0 Answers0