java - How to add a JPanel to a JFrame with Runnable method -


when create jpanel , add jframe , add canvas (space) show jpanel , not of graphics. why showing jpanel when want show both of them @ same time?

source code:http://pastebin.com/cw9e0a8j

if youre intent add canvas inside jpanel try change following lines in source

original code :

frame.add(p); frame.add(space, borderlayout.center); 

suggested code :

 p.add(space);  frame.add(p, borderlayout.center); 

if willing view both jpanel , canvas in jframe try giving positioning canvas also.but different layout better. try out given example.

original code :

    frame.setlayout(new borderlayout());      frame.add(p);     frame.add(space, borderlayout.center); 

suggested code 1 : providing position jpanle in border layout.

    frame.setlayout(new borderlayout());      frame.add(p, borderlayout.north);     frame.add(space, borderlayout.center); 

suggested code 2 : changing layout of jframe.

    frame.setlayout(new gridlayout(0,2));             frame.add(p);     frame.add(space); 

for more information please refer official documentation[1].
[1]. https://docs.oracle.com/javase/tutorial/uiswing/layout/index.html


Comments

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -