Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8853281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:36:49+00:00 2026-06-14T13:36:49+00:00

I’ve a problem with the layout of this applet. Its got a List next

  • 0

I’ve a problem with the layout of this applet. Its got a List next to a Canvas in a border layout. Now sometimes when I run it the list is very narrow, 51 pixels wide. Other times with a tiny change in the code it works fine and the list is wide enough to display the entries. The list is populated from an array and commenting out one item from the array is
enough to change behavior. To be precise commenting this line fixes the problem

{"---- Lissajous curves ","t","t","1","1"}, // commenting this line fixes problem

I suspect this is a bug, but it would be nice to know if its reproducible or if I’m doing something silly. Also not quite sure of right place to submit a bug, I’m using the standard Java on Mac OS X 10.6.8

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.List;

import javax.swing.SwingUtilities;

public class Zap extends Applet {

    private static final long serialVersionUID = 330L;

    String[][] equations = new String[][]{
//                  {"Line ----------------------","3 t-1","t+1"},
                    {"Line","3 t-1","t+1"},
                    {"Circle","cos(t)","sin(t)","-pi","pi"},
                    {"Sq Circle","cos(t)","2 sin(t)","-pi","pi"},
                    {"Ellipse","2 cos(t)","sin(t)","-pi","pi"},
                    {"Cycloid","t-sin(t)","1-cos(t)","-20","20"},
                    {"---- Hypocycloids ----"},
                    {"Deltoid","2 cos(t)+cos(2t)","2 sin(t)-sin(2t)","-pi","pi"},
                    {"Astroid","cos(t)^3","sin(t)^3","-pi","pi"},
                    {"Hypocycloids 5","cos(t) + cos(4 t)/4","sin(t) - sin(4 t)/4","-pi","pi" },
                    {"---- Epicycloids ----"},
                    {"Cardioid",
                            "cos(t) - cos(2 t)/2",
                            "sin(t) - sin(2 t)/2","-pi","pi" },
                    {"Nephroid",
                                            "cos(t) - cos(3 t)/3",
                                            "sin(t) - sin(3 t)/3","-pi","pi" },
                    {"Epicycloid 3",
                                                    "cos(t) - cos(4 t)/4",
                                                    "sin(t) - sin(4 t)/4","-pi","pi" },
                    {"Epicycloid 4",
                                                            "cos(t) - cos(5 t)/5",
                                                            "sin(t) - sin(5 t)/5","-pi","pi" },
                    {"Epicycloid 4",
                                                            "cos(t) - cos(5 t)/5",
                                                            "sin(t) - sin(5 t)/5","-pi","pi" },
                    {"Epicycloid 5",
                                                                    "cos(t) - cos(6 t)/6",
                                                                    "sin(t) - sin(6 t)/6","-pi","pi" },

                    {"---- Lissajous curves ","t","t","1","1"}, // commenting this line
                    {"Lissajous 1,2","sin(t)","sin(2 t)","-pi","pi"},
                    {"Lissajous 1,3","sin(t-pi/2)","sin(3 t)","-pi","pi"},
                    {"Lissajous 1,4","sin(t)","sin(4 t)","-pi","pi"},//             {"a Lissajousxxxxxxxxxxb",""},
                    {"Lissajous 2,1","sin(2t)","sin(t)","-pi","pi"},
                    {"Lissajous 2,2","sin(2t-pi/4)","sin(2t)","-pi","pi"},
                    {"Lissajous 2,3","sin(2t-pi/3)","sin(3t)","-pi","pi"},
                    {"Lissajous 3,4","sin(3t)","sin(4t)","-pi","pi"},
    };



    /** The canvas for plotting the graph */
    private Canvas graphCanvas;

    /** List of equations */
    List list = new List();

    /**
     * Initializes the applet FunctionPlotter
     */
    @Override
    public void init ()  {
        try {
            initComponents();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * Sets the layout of the applet window to BorderLayout, creates all
     * the components and associates them with event listeners if necessary.
     * @param j
     * @throws JepException
     */
    private void initComponents ()  {
        setLayout(new BorderLayout());

//        GridBagConstraints gbc1 = new GridBagConstraints(0, 0, 1, 1,0.9, 1, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0 , 0) ;
//        GridBagConstraints gbc2 = new GridBagConstraints(1, 0, 1, 1, 0.1, 1, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0);
//        setBackground (java.awt.Color.white);

//        list.addItemListener(this);
        list.setMinimumSize(new Dimension(220, 200));
        list.setSize(new Dimension(220, 200));
        list.setPreferredSize(new Dimension(220, 200));
        System.out.println("list "+list.getBounds());
        System.out.println("list ps"+list.getPreferredSize());
        //add(list,gbc2);
        add("East",list);
        for(String[] eles:equations) {
            list.add(eles[0]);
    }
        // create the graph canvas and add it
        graphCanvas = createGraphCanvas();
        //add (graphCanvas,gbc1);
        add("Center",graphCanvas);
        System.out.println("list ps before validate"+list.getPreferredSize());
        list.validate();
        this.validate();
        System.out.println("list ps after validate"+list.getPreferredSize());
        System.out.println(((Object)list).toString());
        System.out.println("\n\n");
    }


    protected Canvas createGraphCanvas()  {
          Canvas gc = new Canvas();
        gc.setPreferredSize(new Dimension(300,300));
        gc.setSize(new Dimension(300,300));
        System.out.println("PC size "+gc.size());
        return gc;
    }

    public static void main(String argv[]) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
    protected static void createAndShowGUI() {
            Frame f = new Frame();
            f.setSize(600, 400);
            Zap pp = new Zap();
            f.add(pp);
            pp.init();
            System.out.println("pack");
        //f.pack();
            System.out.println("setVis");
            f.setVisible(true);
            System.out.println("setVis done");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:36:50+00:00Added an answer on June 14, 2026 at 1:36 pm

    Try this (Swing based) variant of the list.

    Zap

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import javax.swing.*;
    
    public class Zap extends JPanel {
    
        private static final long serialVersionUID = 330L;
    
        String[][] equations = new String[][]{
                //                  {"Line ----------------------","3 t-1","t+1"},
                {"Line","3 t-1","t+1"},
                {"Circle","cos(t)","sin(t)","-pi","pi"},
                {"Sq Circle","cos(t)","2 sin(t)","-pi","pi"},
                {"Ellipse","2 cos(t)","sin(t)","-pi","pi"},
                {"Cycloid","t-sin(t)","1-cos(t)","-20","20"},
                {"---- Hypocycloids ----"},
                {"Deltoid","2 cos(t)+cos(2t)","2 sin(t)-sin(2t)","-pi","pi"},
                {"Astroid","cos(t)^3","sin(t)^3","-pi","pi"},
                {"Hypocycloids 5","cos(t) + cos(4 t)/4","sin(t) - sin(4 t)/4","-pi","pi" },
                {"---- Epicycloids ----"},
                {"Cardioid",
                    "cos(t) - cos(2 t)/2",
                    "sin(t) - sin(2 t)/2","-pi","pi" },
                    {"Nephroid",
                        "cos(t) - cos(3 t)/3",
                        "sin(t) - sin(3 t)/3","-pi","pi" },
                        {"Epicycloid 3",
                            "cos(t) - cos(4 t)/4",
                            "sin(t) - sin(4 t)/4","-pi","pi" },
                            {"Epicycloid 4",
                                "cos(t) - cos(5 t)/5",
                                "sin(t) - sin(5 t)/5","-pi","pi" },
                                {"Epicycloid 4",
                                    "cos(t) - cos(5 t)/5",
                                    "sin(t) - sin(5 t)/5","-pi","pi" },
                                    {"Epicycloid 5",
                                        "cos(t) - cos(6 t)/6",
                                        "sin(t) - sin(6 t)/6","-pi","pi" },
    
                                        {"---- Lissajous curves ----","t","t","1","1"}, // commenting this line
                                        {"Lissajous 1,2","sin(t)","sin(2 t)","-pi","pi"},
                                        {"Lissajous 1,3","sin(t-pi/2)","sin(3 t)","-pi","pi"},
                                        {"Lissajous 1,4","sin(t)","sin(4 t)","-pi","pi"},//             {"a Lissajousxxxxxxxxxxb",""},
                                        {"Lissajous 2,1","sin(2t)","sin(t)","-pi","pi"},
                                        {"Lissajous 2,2","sin(2t-pi/4)","sin(2t)","-pi","pi"},
                                        {"Lissajous 2,3","sin(2t-pi/3)","sin(3t)","-pi","pi"},
                                        {"Lissajous 3,4","sin(3t)","sin(4t)","-pi","pi"},
        };
    
        /** The canvas for plotting the graph */
        private JPanel graphCanvas;
    
        DefaultListModel model = new DefaultListModel(); 
        /** List of equations */
        JList list = new JList(model);
    
        /**
         * Initializes the FunctionPlotter
         */
        public void init ()  {
            try {
                initComponents();
    
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        /**
         * Sets the layout of the applet window to BorderLayout, creates all
         * the components and associates them with event listeners if necessary.
         * @param j
         * @throws JepException
         */
        private void initComponents ()  {
            setLayout(new BorderLayout());
            System.out.println("list "+list.getBounds());
            System.out.println("list ps"+list.getPreferredSize());
            list.setVisibleRowCount(8);
            JScrollPane scroll = new JScrollPane(
                    list, 
                    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER
                    );
            add(BorderLayout.LINE_END,scroll);
    
            for(String[] eles:equations) {
                model.addElement(eles[0]);
            }
    
            // create the graph canvas and add it
            graphCanvas = createGraphCanvas();
            //add (graphCanvas,gbc1);
            add("Center",graphCanvas);
        }
    
        protected JPanel createGraphCanvas()  {
            JPanel gc = new JPanel() {
    
                @Override
                public void paintComponent(Graphics g) {
                    super.paintComponent(g);
                    g.setColor(Color.GREEN.darker());
                    g.fillRect(0, 0, getWidth(), getHeight());
                }
            };
    
            gc.setPreferredSize(new Dimension(300,10));
            return gc;
        }
    
        public static void main(String argv[]) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
        }
        protected static void createAndShowGUI() {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            Zap pp = new Zap();
            f.add(pp);
            pp.init();
            System.out.println("pack");
            f.pack();
            System.out.println("setVis");
            f.setVisible(true);
            System.out.println("setVis done");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.