我有一个JscrollPane,其JPanel实现了Scrollable作为它的视口视图。当我将ScrollableTracksViewportHeight和ScrollableTracksViewportWidth设置为false时,我的面板保持其首选大小。好。问题是,我无法弄清谁在滚动面板周围拥有空间。我觉得我已经尝试改变每个组件和对话框的背景,似乎没有任何东西可以做到。我该如何将丑陋的灰色变成霓虹黄色这样有趣的颜色?谁拥有Java Swing可滚动视口边缘的颜色?
这里就是我谈论的截图:
这里就是我想:
下面是复制的第一图像的代码:
package components;
import java.awt.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class DialogWithScrollPane extends JFrame {
ScrollablePanel scrollablePanel;
public DialogWithScrollPane() {
super();
setResizable(true);
Container pane = getContentPane();
scrollablePanel = new ScrollablePanel();
final JScrollPane scrollPane = new JScrollPane();
scrollPane.setPreferredSize(new Dimension(300,300));
scrollPane.setViewportView(scrollablePanel);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
pane.add(scrollPane);
setMinimumSize(new Dimension(300, 300));
setVisible(true);
}
class ScrollablePanel extends JPanel implements Scrollable {
public ScrollablePanel() {
super();
setBackground(Color.red);
setPreferredSize(new Dimension(200, 100));
}
public Dimension getPreferredScrollableViewportSize() {
return getPreferredSize();
}
public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
return 0;
}
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
return 0;
}
public boolean getScrollableTracksViewportHeight() {
return false;
}
public boolean getScrollableTracksViewportWidth() {
return false;
}
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
new DialogWithScrollPane();
}
});
}
}
为清晰起见+1! – trashgod