java - How do I fix the height of a JEditorPane inside a JScrollPane? -


i want restrict height of jeditorpane inside jscrollpane have maximum value, still allow width expand fit content.

my reasoning want single line of text allows me embed components. want jtextfield embeddable components, since jtextfield cannot this, i'm using jeditorpane (jtextpane fine, too).

i'm trying mimic stackoverflow tag behavior in desktop swing application. embed clickable "tags" in jeditorpane , they'll appear in 1 line, does.

as stands, jeditorpane expands vertically, not horizontally sscce:

import javax.swing.*; import java.awt.borderlayout;  public class tags {     /*      * method want modify implement behavior:      */     public static jcomponent buildtagscomponent() {         jscrollpane scrollpane = new jscrollpane();         jeditorpane editorpane = new jeditorpane();         scrollpane.setviewportview(editorpane);         return scrollpane;     }     /*      * remainder of code make example complete.      */     public static jframe buildframe() {         jframe frame = new jframe("tags example");         jpanel panel = new jpanel();         jpanel tagspanel = new jpanel();         jlabel tagslabel = new jlabel("tags:");         jlabel maincontent = new jlabel("main content goes here");         tagspanel.add(tagslabel);         tagspanel.add(buildtagscomponent());         panel.setlayout(new borderlayout());         panel.add(tagspanel,borderlayout.south);         panel.add(maincontent,borderlayout.center);         frame.setcontentpane(panel);         return frame;     }     public static void main(string[] args) {         swingutilities.invokelater(             new runnable() {                 public void run() {                     jframe frame = buildframe();                     frame.pack();                     frame.setvisible(true);                 }             }         );     } } 

note plan disable scrollbars , require scrolling gesture or moving cursor position cursor keys. when added "never" scrollbar policies, made things not scrollable @ all. i'm not looking solution scrolling problem right now, want answers take account setting scrollbar policy never horizontal , vertical.

i've tried explicitly setting height , width (minimum, preferred, , maximum) 12 , integer.max_value, respectively.

update

after research believe solution i'm looking has word wrapping. want jeditorpane not wrap paragraphs when there no line break (line feed).

currently, editor pane not resize horizontally because of layout manager. default jpanel flowlayout, sizes components @ fixed preferred size.

try boxlayout:

jpanel tagspanel = new jpanel(); tagspanel.setlayout(new boxlayout(tagspanel, boxlayout.line_axis)); // add components 

extra tip: improve of panel, can add invisible components (that put space between other components), and/or empty border (that creates margin other components:

tagspanel.add(tagslabel); tagspanel.add(box.createrigidarea(new dimension(10,0))); tagspanel.add(buildtagscomponent()); tagspanel.setborder(borderfactory.createemptyborder(5,5,5,5)); 


regarding problem of line wrapping (which cannot deactivate in jeditorpane, unlike in jtextarea), solution proposed here (referenced this post).

basically have extend stylededitorkit , set jeditorpane.


regarding behaviour of jscrollpane, maybe solution use as_needed default setting, customize ui of scroll bars make size equal zero. way have scrolling behaviour without scroll bars themselves.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -