I'm writing an application using swing and I want to stretch out the JTextPane to take whole possible space. For now, there is nothing in there except the JTextPane, but it takes only the space it needs, when due to aesthetics I want it to take whole possible space. Preferably I would like to do it with layouts, instead of using fixed size. Currently I use BorderLayout.
public class FileView extends JPanel { private ModelInterface model; private JTextPane textPane = new JTextPane(); // creating TextPane public FileView(ModelInterface model) { this.model = model; add(textPane); refreshFile(); } ... // thats how I append new lines to the TextPane. TextPane can also be modified from client view private void appendToPane(JTextPane textPane, String msg, Color c) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED); int len = textPane.getDocument().getLength(); textPane.setCaretPosition(len); textPane.setCharacterAttributes(aset, false); textPane.replaceSelection(msg); }}
public class FileView extends JPanel { private ModelInterface model; private JTextPane textPane = new JTextPane(); // creating TextPane public FileView(ModelInterface model) { this.model = model; add(textPane); refreshFile(); } ... // thats how I append new lines to the TextPane. TextPane can also be modified from client view private void appendToPane(JTextPane textPane, String msg, Color c) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED); int len = textPane.getDocument().getLength(); textPane.setCaretPosition(len); textPane.setCharacterAttributes(aset, false); textPane.replaceSelection(msg); }}
Similar Threads
Recent Announcements
Continue the conversation
Join the Discord to ask follow-up questions and connect with the community
JC|HCL
Java Community | Help. Code. Learn.
We are a Community full of Java developers. Connect with other devs, get help, help others and do much more!