hallo zusammen,
es geht wiedermal um das neuzeichnen eines jscrollpanes. Mittlerweile hab ich schon Tagelang gesucht und nichts gefunden, was irgendwas gebracht hat.
Undzwar sieht es folgendermaßen aus:
Ich arbeite mit Netbeans 6.7.1. Damit hab ich mir eine GUI gebastelt (ganz rudimentär, nur mit einer jScrollPane). Neben der GUI-Klasse habe ich auch noch eine Main Klasse die die GUI-Klasse initialisiert und anzheigen lässt.
Bei dem Prozess wird eine PagePane ins jScrollPane geladen und beim starten auch super angezeigt. Die PagePane enthält eine PDF. Bei der Ausführung wird diese gut angezeigt. Wenn ich allerdings an die PDF ranzoome (mit dem zoomtool - in der PagePaneklasse) wird die PDF vergrößert, allerdings passen sich die Scrollbalken meiner jScrollpane nicht mehr an... ich kann also zoomen, allerdings nicht über die ganze pdf scrollen. ich gehe also stark davon aus, dass ich die jscrollpane aktualisieren muss. Und genau das funktioniert nicht. Ich kann auch nicht die größe ändern und nichts...
Folgendes habich schon probiert:
sämtliche kombinationen mit:
jscrollpane1.validate()
jscrollpane1.revalidate()
jscrollpane1.getViewport().validate() / revalidate()
das in kombi mit
jscrollpane.repaint() bzw .getViewport().repaint.
über die parent methode:
((JComponent)jscrollpane1.getParent()).revalidate()
wenn man jscrollpane1.isValidateRoot() aufruft, ist dieser ausdruck true
hoffe ihr könnt mir helfen. Es geht um mein Abschlussprojekt meiner Ausbildung und wirklich nichts und niemand konnte mir bisher bei dem problem helfen...
hier nochmal die klassen:
Es befindet sich noch ein button in "myJFrame" drauf: jButton1ActionPerformed ruft die "resize" methoden auf... beim klick tut sich allerdings nichts...
myJFrame (die Gui klasse)
main - die aufrufende mainklasse
ProgressBar - eigentlich unwichtig, nur der vollständigkeit halber
gruß
daniel
es geht wiedermal um das neuzeichnen eines jscrollpanes. Mittlerweile hab ich schon Tagelang gesucht und nichts gefunden, was irgendwas gebracht hat.
Undzwar sieht es folgendermaßen aus:
Ich arbeite mit Netbeans 6.7.1. Damit hab ich mir eine GUI gebastelt (ganz rudimentär, nur mit einer jScrollPane). Neben der GUI-Klasse habe ich auch noch eine Main Klasse die die GUI-Klasse initialisiert und anzheigen lässt.
Bei dem Prozess wird eine PagePane ins jScrollPane geladen und beim starten auch super angezeigt. Die PagePane enthält eine PDF. Bei der Ausführung wird diese gut angezeigt. Wenn ich allerdings an die PDF ranzoome (mit dem zoomtool - in der PagePaneklasse) wird die PDF vergrößert, allerdings passen sich die Scrollbalken meiner jScrollpane nicht mehr an... ich kann also zoomen, allerdings nicht über die ganze pdf scrollen. ich gehe also stark davon aus, dass ich die jscrollpane aktualisieren muss. Und genau das funktioniert nicht. Ich kann auch nicht die größe ändern und nichts...
Folgendes habich schon probiert:
sämtliche kombinationen mit:
jscrollpane1.validate()
jscrollpane1.revalidate()
jscrollpane1.getViewport().validate() / revalidate()
das in kombi mit
jscrollpane.repaint() bzw .getViewport().repaint.
über die parent methode:
((JComponent)jscrollpane1.getParent()).revalidate()
wenn man jscrollpane1.isValidateRoot() aufruft, ist dieser ausdruck true
hoffe ihr könnt mir helfen. Es geht um mein Abschlussprojekt meiner Ausbildung und wirklich nichts und niemand konnte mir bisher bei dem problem helfen...
hier nochmal die klassen:
Es befindet sich noch ein button in "myJFrame" drauf: jButton1ActionPerformed ruft die "resize" methoden auf... beim klick tut sich allerdings nichts...
myJFrame (die Gui klasse)
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* myJFrame.java
*
* Created on 23.03.2010, 11:14:03
*/
package pdftest;
import com.sun.pdfview.PDFPage;
import com.sun.pdfview.PagePanel;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
/**
*
* @author dan
*/
public class myJFrame extends javax.swing.JFrame {
/** Creates new form myJFrame */
public myJFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jToolBar1 = new javax.swing.JToolBar();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jScrollPane1.setAutoscrolls(true);
jToolBar1.setRollover(true);
jButton1.setIcon(new javax.swing.ImageIcon("/home/dan/Desktop/Mac/icons/icons grey/16x16/Zoom Out.png")); // NOI18N
jButton1.setFocusable(false);
jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jToolBar1.add(jButton1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 622, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(63, 63, 63)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 470, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(117, 117, 117))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) //Hier findet die Aktualisierung statt{
// attr_panel.setClip(null);
jScrollPane1.getViewport().setView(attr_panel);
jScrollPane1.getViewport().revalidate();
jScrollPane1.getViewport().repaint();
}
/**
* @param args the command line arguments
*/
// public static void main(String args[]) {
// java.awt.EventQueue.invokeLater(new Runnable() {
// public void run() {
// new myJFrame().setVisible(true);
// }
// });
// }
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JToolBar jToolBar1;
// End of variables declaration
public void setpane(PagePanel panel){
attr_panel = panel;
panel.useZoomTool(true);
jScrollPane1.getViewport().add(panel);
}
private PagePanel attr_panel;
}
main - die aufrufende mainklasse
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pdftest;
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
import com.sun.pdfview.PagePanel;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
/**
*
* @author dan
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
ProgressBar JFramePB = new ProgressBar();
JFramePB.setVisible(true);
URL u = new URL("http://localhost/test.pdf");
URLConnection urlc = u.openConnection();
int contentlength = urlc.getContentLength();
InputStream is = urlc.getInputStream();
java.io.BufferedInputStream bis = new java.io.BufferedInputStream(is);
File f = new File("/home/dan/test.pdf");
OutputStream os = new FileOutputStream(f);
int cs = 0;
int count = 0;
do{
os.write(cs = bis.read());
count = count + cs;
JFramePB.actualizeProgressBar(count/contentlength);
}
while(cs!=-1);
JFramePB.setVisible(false);
File file=new File("/home/dan/test.pdf");
RandomAccessFile raf = new RandomAccessFile(file, "r");
FileChannel channel = raf.getChannel();
ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
PDFFile pdffile = new PDFFile(buf);
PDFPage page = pdffile.getPage(0);
PagePanel panel = new PagePanel();
myJFrame mainJFrame = new myJFrame();
mainJFrame.setpane(panel);
mainJFrame.pack();
mainJFrame.setVisible(true);
panel.showPage(page);
}
}
ProgressBar - eigentlich unwichtig, nur der vollständigkeit halber
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* ProgressBar.java
*
* Created on 23.03.2010, 13:04:26
*/
package pdftest;
import javax.swing.JScrollPane;
/**
*
* @author dan
*/
public class ProgressBar extends javax.swing.JFrame {
/** Creates new form ProgressBar */
public ProgressBar() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jProgressBar1 = new javax.swing.JProgressBar();
jLabel1 = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
jSeparator2 = new javax.swing.JSeparator();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Downloading PDF");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 428, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(3, 3, 3)
.addComponent(jLabel1)
.addGap(3, 3, 3)
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
// public static void main(String args[]) {
// java.awt.EventQueue.invokeLater(new Runnable() {
// public void run() {
// new ProgressBar().setVisible(true);
// }
// });
// }
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JProgressBar jProgressBar1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
// End of variables declaration
public void actualizeProgressBar(int percent){
jProgressBar1.setValue(percent);
}
}
daniel
Zuletzt bearbeitet: