gpt4 book ai didi

java - jscrollpane 有拖尾图像

转载 作者:行者123 更新时间:2023-11-29 06:10:51 24 4
gpt4 key购买 nike

enter image description here

我在 JScrollPane 中有一个 JPanel,每当我尝试滚动时它都会这样做。请帮忙! 我该如何解决这个问题?

编辑

JScrollPane pane;
....
pane = new JScrollPane(GC.createGraph());
pane.setPreferredSize(new Dimension(480,480*2/3));

最佳答案

放置为其他人可以看到的答案。如果您不调用 super.paintComponent,您将获得这些工件。例如,

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.*;

public class ScrollPaneArtifacts extends JPanel {
private static final int SPA_WIDTH = 600;
private static final int SPA_HEIGHT = SPA_WIDTH;

@Override
protected void paintComponent(Graphics g) {
//super.paintComponent(g);
g.setColor(Color.red);
g.drawLine(0, 0, getWidth(), getHeight());
g.drawLine(getWidth(), 0, 0, getHeight());
}

@Override
public Dimension getPreferredSize() {
return new Dimension(SPA_WIDTH, SPA_HEIGHT);
}

private static void createAndShowUI() {
JScrollPane scrollpane = new JScrollPane(new ScrollPaneArtifacts());
scrollpane.getViewport().setPreferredSize(new Dimension(400, 400));
JFrame frame = new JFrame("ScrollPaneArtifacts");
frame.getContentPane().add(scrollpane);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
createAndShowUI();
}
});
}
}

关于java - jscrollpane 有拖尾图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6918585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com