• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding Objects to a Frame

 
Gulshan Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code to draw to white boxes in a frame:

The two problems are that the boxes don't display when you display them together, they only work one at a time. The second problem is I'm trying to put a border around each rectangle I draw, but Border blackline = new BorderFactory.createLineBorder(Color.BLACK); says something like BorderFactory.createLineBorder cannot be resolved to a type.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using a Layout for the JPanel that places the two components where you want them.
 
Gulshan Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Try using a Layout for the JPanel that places the two components where you want them.

I tried that... I tried doing something like panel.add(BorderLayout.East, cGrid) and frame.add(BorderLayout.EAST, cGrid). If I do this I can see either of the grids...

I think it has something to do with the fillRect() having specific coordinates. This may be completely wrong but it just seems that positioning something after it has already been placed on certain coordinates doesn't make sense...
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gulshan Singh wrote:
Ulf Dittmer wrote:Try using a Layout for the JPanel that places the two components where you want them.

I tried that... I tried doing something like panel.add(BorderLayout.East, cGrid) and frame.add(BorderLayout.EAST, cGrid). If I do this I can see either of the grids...

I think it has something to do with the fillRect() having specific coordinates. This may be completely wrong but it just seems that positioning something after it has already been placed on certain coordinates doesn't make sense...


Play with it a bit and try different layouts. For instance:

 
Gulshan Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried that solution and I tried many different combinations of solutions with different layouts. They all work fine for any other component, such as a button, but they don't work right when I have a component that is simply a rectangle made with fillRect(). I've looked everywhere for the solution and I really need help...
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gulshan Singh wrote:I tried that solution and I tried many different combinations of solutions with different layouts. They all work fine for any other component, such as a button, but they don't work right when I have a component that is simply a rectangle made with fillRect(). I've looked everywhere for the solution and I really need help...


We can probably better help you (and you can help yourself) by:
1) Simplify the problem. Just work on laying out things in isolation of everything else.
2) Create a compilable program that tries to solve the layout issue.
3) Post your attempt with a detailed explanation of what does and does not work with your attempt.

Much luck.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!