Note that there are some explanatory texts on larger screens.

plurals
  1. POOrder of rectangles to display and can they be changed?
    primarykey
    data
    text
    <p>I working on a project in which I have to simulate a memory manager and show some memory snapshots. I have created a draw class via examples I have found here in which I override the paintComponet(). Everything draws fine.</p> <p>I would like to be able to draw a rectangle to represent a memory partition and then overlay another rectangle over top to represent an incoming job (ie Job1 is in this partition3). What seems to occur is that I add the partition first (which will always be the case) and then when I add the job it will sit behind the partition block. Is there a way other than drawing the Job first to shift these after the job is created?</p> <p>Here is the paint override</p> <pre><code>@Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; // set up rendering to allow anti-aliasing g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // create the rectangle to represent the memory partition block // x = address position h = amount of memory (y &amp; w are predefined for the display block) Rectangle2D rect = new Rectangle2D.Double(x, y, w, h); // create the rectangle g2d.setPaint(partColor); // set it's color g2d.fill(rect); // fill it in // create the transparency for the text Composite comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .4f); g2d.setComposite(comp); // draw the text with color, type and size and center the text in the block created above g2d.setPaint(Color.black); g2d.setFont(new Font("Tahoma", Font.PLAIN, 12)); g2d.drawString(text, (int)((w / 2) - (text.length()/2)), (int)h/2); } </code></pre> <p>The call to draw is in my window class (this will place the partition in front of the job) but I need to order to be reversed without changing the order of the calls.</p> <pre><code> // Draw both Text and Block with transparency DrawPartition part1 = new DrawPartition(Color.blue, 0, 0, 110, 100, "part1"); part1.setBounds(5, 5, 110, 100); snapPanel.add(part1); DrawJob job1 = new DrawJob(Color.green, 0, 0, 110, 100, "Job 1"); job1.setBounds(5, 15, 110, 100); snapPanel.add(job1); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload