Considering no one seems to be-able to answer my other thread I'll try simplifying this one.
I have created GUI frame which contains a menubar at the top. I have several methods as well as a method which paints 5 circles onto the frame. When I call that method, by pressing a certain button, it adds the circles to the frame BUT they are only visible when I resize the frame.

Could this have anything to do with the overall layout used in the frame? Here's the code:

JButton paint = new JButton("Paint Circle");
		paint.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{ 
				MyWidget widget;
				widget = new MyWidget();
				
				myFrame.add(widget, BorderLayout.CENTER);
				System.out.println("Did it work?");
			}
		});     // Ends the method attached to the button

		myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JMenuBar north = new JMenuBar();
		
		north.add(text);
		north.add(b1);
		north.add(generate);
		north.add(setEmpty);
		north.add(paint);
		north.setBackground(Color.BLACK);
		
		myFrame.setJMenuBar(north);
		myFrame.setLayout(new BorderLayout());		
		myFrame.setVisible(true);
		
	}

Any thoughts anyone?

Recommended Answers

All 3 Replies

Yeah; after you add the new widget to the JFrame, call myFrame.validate();

I must say mate, your good
The circles appeared as they should on the frame.
Much appreciated! :D

No problem, mark the thread as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.