First of all I hope it\'s not a problem I started a new topic. Tbh I don\'t have a clue how to ask a question based on an already answered one, so I made this.
I\'m
A deadly better solution I found :
The
is correctly handled by the HTMLEditorKit
, but the Patrick Sebastien's post mentionned that it won't. It's because its ViewFactory
threat all InlineView
object as wrappable, but the BRView
is also an InlineView
. See my solution below:
class WrapColumnFactory extends HTMLEditorKit.HTMLFactory {
@Override
public View create(Element elem) {
View v = super.create(elem);
if (v instanceof LabelView) {
// the javax.swing.text.html.BRView (representing
tag) is a LabelView but must not be handled
// by a WrapLabelView. As BRView is private, check the html tag from elem attribute
Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute);
if ((o instanceof HTML.Tag) && o == HTML.Tag.BR) {
return v;
}
return new WrapLabelView(elem);
}
return v;
}
}
class WrapLabelView extends LabelView {
public WrapLabelView(Element elem) {
super(elem);
}
@Override
public float getMinimumSpan(int axis) {
switch (axis) {
case View.X_AXIS:
return 0;
case View.Y_AXIS:
return super.getMinimumSpan(axis);
default:
throw new IllegalArgumentException("Invalid axis: " + axis);
}
}
}