我想用Rectangle填充Panel以覆盖图像。但是我的代码没有任何反应。你知道为什么?我不想使用setBackground。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="hidden" id="userScore" value="20">
<div data-score="5" class="item">A</div>
<div data-score="15" class="item">B</div>
<div data-score="45" class="item">E</div>
<div data-score="25" class="item">C</div>
<div data-score="35" class="item">D</div>
<hr>
<div id="result">NEXT IS UNKNOWN!</div>
答案 0 :(得分:0)
如果您想以这种方式更改面板背景。您需要像这样覆盖paintComponent方法。
JPanel jYourPanel = new JPanel(){
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//lets paint background
g2.setColor(Color.RED);
g2.fillRect(0, 0, getWidth(), getHeight());
}
}