1 year ago
#244294
Jonas
JEditorPane is blocking the divider of a JSplitPane
In my application I'm using a JSplitPane to devide the GUI into two sides. Every side will contain some components, one of them being a JEditorPane. The components are placed horizontally next to each other. All components should have a fixed size exept for the JEditorPanel. This should take all the available horizontal space. So, if the divider of the splitPane is moved the JEditorPane should change its width. My current implementation works fine if the divider is moved in a direction where the with of the JSplitPane increases. However, it is not possible to move the divider in the other direction. Below is a minimalistic example of my problem. In the example I'm using a GridbagLayout. However, this problem remains also for other layout manager. Also interesting is that this problem seems to be unique for the JEditorPane. The implementation works fine when the JEditorPane is replaced, for example by a JButton. Here is my code:
import javax.swing.*;
import java.awt.*;
public class Test {
public static void main(String[] args) {
JFrame f = new JFrame();
f.setSize(500, 500);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panelRight = new JPanel();
JPanel panelLeft = new JPanel();
panelRight.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
JButton b = new JButton("button");
c.gridx = 1;
c.gridy = 0;
panelRight.add(b, c);
JEditorPane ep = new JEditorPane();
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
c.weightx = 1;
panelRight.add(ep, c);
JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panelLeft, panelRight);
sp.setResizeWeight(0.5);
f.add(sp);
f.setVisible(true);
}
}
Does anyone have an idea why this is happending and/or how to fix it?
java
swing
awt
jeditorpane
jsplitpane
0 Answers
Your Answer