Drawing rectangle that is some percent of drawing-panel

awt, java, java-2d, jpanel, swing

Solution

Try this:

this.getHeight()-(45*this.getHeight())/100

Problem

I want to draw rectangle that is only specified percent high of panel im drawing it on, and when i resize the panel it should resize itself. But my problem is that drawRect() accepts only integers so when i try to draw rectangle for example 45% of panel height it gets converted to 0 if panel height is less than 100. My code is very simple so you can try it out. Here is my code: ``` public class Drawer extends JPanel { @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.fillRect(10,this.getHeight()-this.getHeight()/100*45, 100, this.getHeight()-this.getHeight()/100*45); } } ```

Original source