I’ve tried porting Karga to PureSwing (with default Desktop). Most went quite smootly
below are some issues i’ve faced (some important some not)
- ImageIcon(url) waits indefinetely if given url is an animated gif
- JDesktopPane does not correctly stack (render and dispatch mouse events) components
- JLabel doesn’t support multilines (separated with \n)
- JFrame.pack() does not take window decorations (title bar, borders) into account
- JFrame.setDefaultCloseOperation(CloseOperation.EXIT_ON_CLOSE) does not work
- switching to another window and coming back results in losing keyboard focus. we even can not regain it by clicking
- pressing Tab does not iterate over focusable components
and some opinions:
- re-adding JOptionPane.showInternalXXDialog makes sense to show the dialogs embedded in same window
- re-adding basic HTML support can make sense (JEditorPane, JTextPane, html in JLabel) they are very handy to create multi color/line/format texts.
and below is a test case:
[quote]import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import cz.advel.pureswing.CloseOperation;
import cz.advel.pureswing.EventQueue;
import cz.advel.pureswing.JDesktopPane;
import cz.advel.pureswing.JFrame;
import cz.advel.pureswing.JPanel;
import cz.advel.pureswing.JTextField;
import cz.advel.pureswing.event.MouseAdapter;
import cz.advel.pureswing.event.MouseEvent;
public class MultiLayer {
public static final Integer BACKGROUND_LAYER = new Integer(10);
public static final Integer HELPERS_LAYER = new Integer(30);
public static void main(String[] args) {
JDesktopPane desktop = new JDesktopPane();
desktop.setPreferredSize(new Dimension(800, 600));
JPanel backgroundPanel = new JPanel();
backgroundPanel.setBackground(Color.LIGHT_GRAY);
desktop.add(backgroundPanel, BACKGROUND_LAYER);
// this should be centered in frame but is not
backgroundPanel.setBounds(new Rectangle(50, 50, 700, 500));
backgroundPanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
System.out.println("mouse clicked on background");
}
});
// this text field should be rendered on top of background but is not
JTextField textField = new JTextField();
desktop.add(textField, HELPERS_LAYER);
textField.setBounds(0, 50, 200, 20);
textField.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
System.out.println("mouse clicked on textField");
}
});
JFrame frame = new JFrame("PureSwing - test");
frame.setDefaultCloseOperation(CloseOperation.EXIT_ON_CLOSE);
frame.add(desktop);
frame.pack();
frame.setVisible(true);
EventQueue.runLoop();
}
}
[/quote]
hope this helps,
r a f t