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

  • Home
  • SEARCH
  • 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 3428000
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:54:22+00:00 2026-05-18T06:54:22+00:00

I have the following code. Class KochSnowflakesMenu is a grid JPanel with three buttons.

  • 0

I have the following code. Class KochSnowflakesMenu is a grid JPanel with three buttons. Class KochSnowflakesDraw currently draws a circle using drawOval:

import javax.swing.*;
import java.awt.*;

public class KochSnowflakes
{
    public static void main(String[] args)
    {
        JFrame frame = new JFrame("Koch Snowflakes");
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBounds(0,0, 600, 425);
        frame.setBackground(Color.BLACK);
        frame.setResizable(false);
        frame.setLayout(null);

        // Create the button interface
        frame.add(new KochSnowflakesMenu());
        frame.add(new KochSnowflakesDraw());
        frame.repaint();
    }
}

This works if I comment out frame.setResizable(false). When I don’t the buttons don’t appear. Why is that? As you can see, I have tried using repaint(). I had previously the problem that the buttons would not show up until I manually resized the window…

Also, as a bonus question, if anyone can tell me how to get the dimensions of a JPanel that would be great. The reason why I can’t use a resizable layout manager such as BorderLayout, which really is what I want to use, is that I can’t figure out the dimension of the JPanel that occupies the center (and hence have no idea how to large to draw the things I’m drawing).

EDIT:
As requested, here is the KockSnowflakesMenu class:

import javax.swing.*;
import java.awt.*;

public class KochSnowflakesMenu extends JPanel
{
    public KochSnowflakesMenu()
    {
        setLayout(new GridLayout(3,1));
        setBounds(0,0,200,400);

        JButton button_red = new JButton("Red");
        JButton button_yellow = new JButton("Yellow");
        JButton button_blue = new JButton("Blue");

        add(button_red);
        add(button_yellow);
        add(button_blue);
    }
}

And, just to be sure I didn’t mess something up with KochSnowflakesDraw, here’s that class as well:

import javax.swing.*;
import java.awt.*;

public class KochSnowflakesDraw extends JPanel
{
    public KochSnowflakesDraw()
    {
        setLayout(null);
        setBounds(200, 0, 400, 400);
    }

    public void paintComponent(Graphics g)
    {
        g.setColor(Color.RED);
        g.drawOval(0,0,400, 400);
    }
}
  • 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-05-18T06:54:22+00:00Added an answer on May 18, 2026 at 6:54 am

    Adding more info to the previous answers…
    The size is random until the component is drawn so make sure you have a setVisible(true) on your frame. Here’s your code w/some modifications that let you use the BorderLayout and get the size of your drawing panel. I substituted some fake buttons for your interfaces but you’ll get the drift.

    
    JFrame frame = new JFrame("Koch Snowflakes");
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(0,0, 600, 425);
    frame.setBackground(Color.BLACK);
    frame.setResizable(false);
    frame.setLayout(new BorderLayout());
    
    JPanel buttons = new JPanel(new FlowLayout());
    buttons.add(new JButton("MENU"));
    buttons.add(new JButton("DRAW"));
    frame.add(buttons, BorderLayout.SOUTH);
    
    JPanel drawArea = new JPanel();
    drawArea.setBackground(Color.BLUE);
    frame.add(drawArea, BorderLayout.CENTER);
    frame.setVisible(true);
    Dimension drawAreaDim = drawArea.getSize();
    System.out.println(drawAreaDim);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: using System; using System.Linq; using System.Linq.Expressions; public class Program
I have the following code: class IncidentTag: def __init__(self,tag): self.tag = tag def equals(self,obj):
Suppose I have the following code: class some_class{}; some_class some_function() { return some_class(); }
Suppose I have the following code: class siteMS { ... function __CONSTRUCT() { require
I have the following code: public class Test { public static void Main() {
I have the following example code: class A(object): def __init__(self, id): self.myid = id
Lets say I have the following code: abstract class Animal case class Dog(name:String) extends
I have the following code in my class : sub new { my $class
I have the following code for factory design pattern implementation. class Pen{ public: virtual
I have the following Django and Flex code: Django class Author(models.Model): name = models.CharField(max_length=30)

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.