I have a JXTaskPaneContainer
on the right hand side of my JFrame which contains hyperlinks and labels. The window's main parts should be:
- a large area on the left for the text
- a smaller area on the right with the messages and the actions
Now, the problem is that adding a lot of new elements causes the container to grow to the left and over the text:
It gets even weirder when having the JXTaskPaneContainer
inside a javax.swing.JScrollPane
(video/yt).
The problem seems to lie with the JXLabel. I suspect it's the word wrap? Any ideas how to fix this?
[Example] Self-contained example as per request. Full source on github.
package layoutproblemSSCEC;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import org.jdesktop.swingx.JXButton;
import org.jdesktop.swingx.JXLabel;
import org.jdesktop.swingx.JXTaskPane;
import org.jdesktop.swingx.JXTaskPaneContainer;
public class SwingWindow {
private JFrame frame;
String dolorem = "Sed ut perspiciatis unde omnis iste natus error sit "
+ "voluptatem accusantium doloremque laudantium, totam rem aperiam, "
+ "eaque ipsa quae ab illo inventore veritatis et quasi architecto "
+ "beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem "
+ "quia voluptas sit aspernatur aut odit aut fugit, sed quia "
+ "consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. "
+ "Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, "
+ "consectetur, adipisci velit, sed quia non numquam eius modi tempora "
+ "incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut "
+ "enim ad minima veniam, quis nostrum exercitationem ullam corporis "
+ "suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? "
+ "Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse "
+ "quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat "
+ "quo voluptas nulla pariatur?";
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SwingWindow window = new SwingWindow();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public SwingWindow() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JXTaskPaneContainer panels = new JXTaskPaneContainer();
JScrollPane scrollpanel = new JScrollPane(panels);
Container content = frame.getContentPane();
content.add(new JTextArea(dolorem), BorderLayout.CENTER);
content.add(scrollpanel, BorderLayout.EAST);
content.add(new JXButton(new AbstractAction("Click me") {
public void actionPerformed(ActionEvent arg0) {
JXTaskPane panel = new JXTaskPane("test");
JXLabel lbl = new JXLabel(dolorem);
lbl.setLineWrap(true);
panel.add(lbl);
panels.add(panel);
}
}), BorderLayout.NORTH);
panels.add(new JXTaskPane("Click the button, then resize"));
}
}