dependabot[bot] on maven
Bump xstream from 1.4.12 to 1.4… (compare)
dependabot[bot] on maven
import com.alee.laf.WebLookAndFeel;
import javax.swing.*;
public class Test extends JFrame
{
Test()
{
JEditorPane p = new JEditorPane();
p.setText(
//"sdfsdfsdf sdfsdfsdf sssss s ss s s s s s s s s s ssssssssssssssssssssssss s s ss s sssssssssssssssssssss"
"للهِ تَعالى- لِتَعْمِيمِ النَّفْع بتِلْكَ الجُهُود المُبارَكة فِي هَذا المَيدَان العَظِيم باشَر القِسْمُ العِلْمِيُّ بِمُؤسَّسةِ الشَّيخِ محُمَّد بنِ صالِحٍ العُثَيمِين الخَيريَّةِ واجِباتِه فِي شَرَفِ الإِعْدادِ والتَّجْهِيز للطِّباعةِ والنَّشْر لإِخْراجِ ذَلِكَ التُّراث العِلمِي؛ إنفاذًا للقَواعِدِ والضَّوابِط والتَّوْجِيهاتِ الَّتِي قَرَّرها فَضيلةُ الشَّيخِ رَحِمَهُ اللهُ تَعالى في هَذا الشَّأْنِ.\n" +
"نَسْأل اللهَ تعالى أنْ يَجْعلَ هَذا العَمَلَ خالصًا لِوجهِه الكَريمِ؛ نافِعًا لعِبادِه، وأنْ يَجزِيَ فَضِيلةَ شيخِنا عَنِ الإسلامِ والمسلمِينَ خَيرَ الجزَاء، ويُضَاعِفَ لهُ المثُوبَةَ والأَجْرَ، ويُعليَ دَرَجَتَهُ في المَهْدِيِّينَ، إِنَّه سَمِيعٌ قَرِيبٌ مجُيبٌ."
);
WebLookAndFeel.setLeftToRightOrientation(true);
getContentPane().add(new JScrollPane(p, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
setSize(150, 100);
setVisible(true);
}
public static void main(String[] args)
{
WebLookAndFeel.install();
new Test();
}
}
Well, there are a few things with the wrapping - if you try the English variant it will also not wrap once you increase the size of the window and then shrink it, but that's a specific of how text layouting works within text areas, it is really hard to workaround that properly.
But yes, Arabic text doesn't seem to be wrapped at all on newest WebLaF version or with Metal with any Java version.
Hi @mgarin
Another question. i have this code
searchTree.addCheckStateChangeListener(new CheckStateChangeListener<DefaultMutableTreeNode>()
{
@Override
public void checkStateChanged(WebCheckBoxTree<DefaultMutableTreeNode> searchTree, List<CheckStateChange<DefaultMutableTreeNode>> checkStateChanges)
{
final java.util.List<DefaultMutableTreeNode> checkedNodes = searchTree.getNodes(CheckState.checked);
....
it throws the following exceptio:
java.lang.NullPointerException
at com.alee.extended.tree.NodesPositionComparator.compare(NodesPositionComparator.java:90)
at com.alee.extended.tree.NodesPositionComparator.compare(NodesPositionComparator.java:36)
at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:356)
at java.base/java.util.TimSort.sort(TimSort.java:220)
at java.base/java.util.Arrays.sort(Arrays.java:1306)
at java.base/java.util.ArrayList.sort(ArrayList.java:1720)
at java.base/java.util.Collections.sort(Collections.java:179)
at com.alee.extended.tree.DefaultTreeCheckingModel.getNodes(DefaultTreeCheckingModel.java:137)
at com.alee.extended.tree.WebCheckBoxTree.getNodes(WebCheckBoxTree.java:454)
at com.alee.extended.tree.WebCheckBoxTree.getNodes(WebCheckBoxTree.java:441)
at com.myapp.Indexer$2.checkStateChanged(Indexer.java:489)
at com.alee.extended.tree.DefaultTreeCheckingModel.fireCheckStateChanged(DefaultTreeCheckingModel.java:683)
at com.alee.extended.tree.DefaultTreeCheckingModel.setChecked(DefaultTreeCheckingModel.java:167)
at com.alee.extended.tree.WebCheckBoxTree.setChecked(WebCheckBoxTree.java:467)
at com.myapp.Indexer$22.actionPerformed(Indexer.java:3448)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.AbstractButton.doClick(AbstractButton.java:369)
at java.desktop/javax.swing.AbstractButton.doClick(AbstractButton.java:349)
at com.myapp.Indexer$8$1.run(Indexer.java:1799)
any hint is appreciated. i cannot build a sample case. it is a bit complicated. but the point is that getNodes(CheckState.checked) throws internal NullPointerException
thank you, the exception happens when deleting the nodes. for some reason it is solved by replacing:
WebCheckBoxTree<DefaultMutableTreeNode> searchTree = new WebCheckBoxTree<>(searchRoot);
with
WebCheckBoxTree<DefaultMutableTreeNode> searchTree = new WebCheckBoxTree<>(new DefaultTreeModel(searchRoot));
really no clue what is happening (and i do not recall if the old code was working with swing laf or not) . so please just ignore this case and thank you
DefaultTreeModel
is because WebCheckBoxTree
uses custom WebTreeModel
by default which is somewhat different and might not tolerate some cases that default Swing model does. I'll try to find and fix the bug for the v1.2.14 update.
I've tried the Lato-Regular.ttf (taken from here: https://github.com/google/fonts/blob/master/ofl/lato/Lato-Regular.ttf ) and it works just fine for me. I've tested it on different JDK versions (6, 8, 9, 11 and 13) and different L&F (Metal and WebLaF) under Windows OS - behavior seems to be exactly the same across all tests - caret is properly positioned on the text in JTextField
with both short and long texts at any index in that text.
So I'll need more details about cases when you see the issue:
MetalLookAndFeel
?
Yep, exactly the same code I've used in my test class:
public class FontTest
{
public static void main ( final String[] args )
{
SwingUtilities.invokeLater ( new Runnable ()
{
@Override
public void run ()
{
try
{
UIManager.setLookAndFeel ( WebLookAndFeel.class.getCanonicalName () );
// UIManager.setLookAndFeel ( MetalLookAndFeel.class.getCanonicalName () );
final Font font = Font.createFont (
Font.TRUETYPE_FONT,
FontTest.class.getResourceAsStream ( "Lato-Regular.ttf" )
).deriveFont ( 16f );
final JFrame frame = new JFrame ();
frame.setLayout ( new FlowLayout () );
final JTextField textField = new JTextField ( 50 );
textField.setFont ( font );
frame.add ( textField );
frame.setSize ( 800, 600 );
frame.setLocationRelativeTo ( null );
frame.setDefaultCloseOperation ( WindowConstants.EXIT_ON_CLOSE );
frame.setVisible ( true );
}
catch ( final Exception e )
{
e.printStackTrace ();
}
}
} );
}
}
I recommend you to try this small example and see if the same issue occurs or not, once with WebLaF and once with the MetalLookAndFeel
.
If it doesn't appear on this example - it might have something to do with other settings in your application.
If it does - then it could be a Java issue on Mac OS, especially if it appears for you on both L&Fs.
I'd say it's a 50/50, it might be caused by hidpi display, but on hidpi I would expect caret in text field to be visually offset by a fixed amount of pixels. The fact that offset increases with larger index means that there is a difference in caret position calculation and font rendering - caret position calculation either uses old font or has some deeper issues.
If it's the same on MetalLookAndFeel
that means it's just a general Java issue, potentially with particular font (or all non-system/custom fonts?) - hard to tell really.
After a quick search on the matter I found this issue: https://bugs.openjdk.java.net/browse/JDK-8014069
It does seem to be resolved long ago though, but it sure does resemble your description of the problem.
Overall - I can't really do anything about font-related issues like this one because both font rendering and font-related calculations aren't done by L&F code and are simply retrieved from public APIs (like FontMetrics
for instance). There could definitely be cases where WebLaF is at fault, but that would usually be reproducible against other L&Fs and would mostly cause the same issues across different OS versions.
What I could recommend doing - try the same example with newer Java versions (9+) and see if the same issue appears there. If newer Java version fixes it - it might be worth switching your application over to newer version if it is possible.
Alternatively - the issue seem to be caused by custom font's size being different from the default font size of the component. Maybe it would work correctly if you use the same font size as the component has by default for your custom font. That's just an idea for a possible workaround.
Also if the issue is still there for you on latest Java 8 updates or even newer Java versions - it might be worth submitting a JDK bug report. I've found quite a few JDK bugs over the years and submitted most of them. Some have been fixed since and some unfortunately are still not resolved, so that could take a long while. Also fixes for reported bugs will most probably only be available on newer Java versions.
@kovadam69 Right now - only if you use some 3rd-party solution or make one yourself. WebLaF currently provides close to none features on top of the basic JTable
, so functionality-wise WebTable
is pretty much the same as JTable
with just a few convenience methods added on top.
We did have a similar task for one of our internal projects - to make a useable multi-line table header - but I wasn't the one working on it and the final solution was quite sloppy and only worked for that particular case, so it didn't make it into WebLaF in the end.
I do plan to eventually expand JTable
to support multi-line header, cells merging, better sorting and some other features I really want to see myself, but it all requires quite an extensive rework of the basic table implementation (both UI and component), so that will most probably be a completely separate new component - something like WebExTable
- and it will take a substantial amount of time to add, which I probably won' have this year.
There are already quite a few issues added for JTable
: https://github.com/mgarin/weblaf/issues?q=is%3Aissue+is%3Aopen+table
I'll make a summary issue now that will list all the planned improvements that are split into separate issues and which you can track.
@kovadam69
If you meant 1.3.0 snapshot - it have been purely experimental and I wouldn't recommend using it.
Currently latest version is 1.2.13, and latest snapshot is 1.2.14.
There have been some important changes done to WebStyledLabel
in one of 1.2.14 commits: mgarin/weblaf@0a39e8c
They might have affected the table title rendering, but I'll have to double-check that.
Judging by the screenshots - table header size calculations remained the same, but label doesn't fit into the available width anymore.
Can you give that specific title text or does this issue appear on any text?
Is this text containing HTML by any chance?
If it is an HTML with <br>
tag, can you try using {br}
(since renderer is a WebStyledLabel
this should work) instead to see if it fixes the issue?
WebLookAndFeel.install();
final WebMemoryBar memoryBar = new WebMemoryBar ();
memoryBar.setPreferredWidth ( 200 );
WebPanel panel = new WebPanel();
panel.setPreferredSize(400, 28);
WebStyledLabel label = new WebStyledLabel();
label.setWrap(TextWrap.word);
label.setText("Asdfasdf 12345678-12345678-12345667 AA123456781234556767");
label.setBoldFont();
panel.add(label);
TestFrame frame = TestFrame.show(5, false, panel, memoryBar);
setBoldFont()
call, but it made no difference
AbstractContentLayout.layoutContent
method. It gets the correct bounds of 427x77, but at the call to final ContentLayoutData layoutData = layoutContent ( c, d, bounds );
it gets back a smaller rectangle. It happens in IconTextLayout
for some reason it reduces the size...
Thanks for code example, I'll look into that.
It is really weird though, maybe the issue is tied to the particular wrapping method or something else very specific.
I have thoroughly tested WebStyledLabel
changes when they were pushed and it didn't seem to have such glaring problems.
One more thing - what Java version are you using for the test?
@kovadam69
Just a small update - I've passed this issue to my colleague who made the recent changes, he will look into it once he has a bit more free time. There are certainly some issues with internal size calculations. It's been a wack-a-mole game for a while with the styled label layouting code as there are just too many cases (especially edge cases) which it needs to account for and the code itself is a bloody mess. Fixing one issue in that part almost always caused a few new ones, just like this time, so we'll need to be very careful.
So as I mentioned earlier - I recommend using more stable public v1.2.13 release for now, at least until v1.2.14 is patched up and finally released.