Note that there are some explanatory texts on larger screens.

plurals
  1. POJScrollPane hides the JTextPane
    text
    copied!<p>![enter image description here][1]I have following structure</p> <pre><code>JFrame JPanel JScrollPane class that extends JTextPane </code></pre> <p>After Adding long text JScrollPane hides the JTextPane.</p> <p>I'm using Gridbag layout.</p> <p>I have DefaultStyledDocument inside clss that extends JTextPane.</p> <p>I have set Maximum size for JTextPane with</p> <pre><code>text.setMaximumSize(new Dimension(100,50)); </code></pre> <p>package com.example;</p> <pre><code>import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.text.DefaultStyledDocument; public class Test extends JFrame{ IPanel p; public Test() { p = new IPanel(); p.init(); setTitle("Test"); setBounds(50, 50, 200, 200); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); add(p); setVisible(true); } public static void main(String[] args) { Test t = new Test(); } } class IPanel extends JPanel{ public void init() { GridBagConstraints gbc = new GridBagConstraints(); GridBagLayout gridbag = new GridBagLayout(); JLabel subjectLabel = new JLabel("Text"); gbc.weighty = 0.0; gbc.gridwidth = 1; gbc.weightx = 0.0; gbc.anchor = GridBagConstraints.NORTH; gridbag.setConstraints(subjectLabel, gbc); add(subjectLabel); TextPane Text = new TextPane(255); Text.setMaximumSize(new Dimension(100,20)); Text.setPreferredSize(new Dimension(100,20)); gridbag.setConstraints(Text, gbc); JScrollPane subScrollPane = new JScrollPane(Text); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.insets = new Insets(0, 0, 5, 0); gridbag.setConstraints(subScrollPane, gbc); subScrollPane.setWheelScrollingEnabled(false); add(subScrollPane); } } class TextPane extends JTextPane{ private Doc doc = new Doc(); public TextPane(int lenght) { doc.setmaxLength(lenght); } } class Doc extends DefaultStyledDocument{ private int maxLength = 0; public void setmaxLength(int lenght) { maxLength = lenght; } } </code></pre> <p>This is code example</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload