У меня есть эта маленькая программа для показа изображений на apanel .. но я не в состоянии добавить свиток к нему .. и это мой кодДобавить JScrollPane на панель, которая показывает изображение
класс, расширяет JPanel, чтобы показать изображение:
public class ShowPanel extends JPanel{
public ShowPanel(BufferedImage image, int height, int width) {
this.image = image;
this.height = height;
this.width = width;
//this.setBounds(width, width, width, height);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, height, width, null);
}
public void setImage(BufferedImage image, int height, int width) {
this.image = image;
this.height = height;
this.width = width;
}
private BufferedImage image;
private int height;
private int width;
}
и образец основной рамы, которая имеет другую панель под названием imageContainer провести демонстрационную панель:
public class MainFrame extends javax.swing.JFrame {
/** Creates new form MainFrame */
public MainFrame() {
initComponents();
image = null;
path = "PantherOnLadder.gif";
image = Actions.loadImage(path);
showPanel = new ShowPanel(image, 0, 0);
spY = toolBar.getY() + toolBar.getHeight();
showPanel.setBounds(0, spY, image.getWidth(), image.getHeight());
showPanel.repaint();
imageContainer.add(showPanel);
JScrollPane scroller = new JScrollPane(imageContainer);
scroller.setAutoscrolls(true);
}
Так что же я ошибся здесь?
спасибо .. хорошо, я также сделаю скальниг и атер на картинке – CiCi
, но даже масштабирование можно обработать, просто переопределив метод «paint» на JLabel – aperkins