Hi,
I am new to ULC and am having some problems with my first few attempts to
check if ULC will work for my planned software. I need to use paintComponent
as in the basic 'MyPanel' example below. I have searched the old posts
here and found an example that uses 'UiJPanel' that would seem to be an
option, however I can't find the '*import* com.ulcjava.base.client.UiJPanel'.

Can somebody please point me in the right direction. Is there a ULC
substitute for JPanel ?? If not is there any examples as to how I go about
painting a grid or likewise that would help me get started.
Thank you for any help.
Al

package painting;

import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
public class SwingPaintDemo2 {

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

    private static void createAndShowGUI() {
        System.out.println("Created GUI on EDT? "+
        SwingUtilities.isEventDispatchThread());
        JFrame f = new JFrame("Swing Paint Demo");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new MyPanel());
        f.pack();
        f.setVisible(true);
    }
}

class MyPanel extends JPanel {

    public MyPanel() {
        setBorder(BorderFactory.createLineBorder(Color.black));
    }

    public Dimension getPreferredSize() {
        return new Dimension(250,200);
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        // Draw Text
        g.drawString("This is my custom Panel!",10,20);
    }
}

Reply via email to