S
Spellsleeper
Gast
Hallo,
ich möchte in einen Dialog ein JScrollPane einbauen, bekomme allerdings diese Fehlermeldung:
[WR]
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: invalid verticalScrollBarPolicy
at javax.swing.JScrollPane.setVerticalScrollBarPolicy(Unknown Source)
at javax.swing.JScrollPane.<init>(Unknown Source)
at main.KeyDialog.<init>(KeyDialog.java:119)
at main.MainFrame$7.actionPerformed(MainFrame.java:498)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: invalid verticalScrollBarPolicy
at javax.swing.JScrollPane.setVerticalScrollBarPolicy(Unknown Source)
at javax.swing.JScrollPane.<init>(Unknown Source)
at main.KeyDialog.<init>(KeyDialog.java:119)
at main.MainFrame$7.actionPerformed(MainFrame.java:498)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)[/WR]
Hier ist die Dialogklasse, ist leider schon etwas unübersichtlich geworden, der Fehler scheint im Konstruktor bei der Initialisierung sp1 und sp2 zu sein.
Wäre cool wenn jemand das Problem entdecken würde
ich möchte in einen Dialog ein JScrollPane einbauen, bekomme allerdings diese Fehlermeldung:
[WR]
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: invalid verticalScrollBarPolicy
at javax.swing.JScrollPane.setVerticalScrollBarPolicy(Unknown Source)
at javax.swing.JScrollPane.<init>(Unknown Source)
at main.KeyDialog.<init>(KeyDialog.java:119)
at main.MainFrame$7.actionPerformed(MainFrame.java:498)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: invalid verticalScrollBarPolicy
at javax.swing.JScrollPane.setVerticalScrollBarPolicy(Unknown Source)
at javax.swing.JScrollPane.<init>(Unknown Source)
at main.KeyDialog.<init>(KeyDialog.java:119)
at main.MainFrame$7.actionPerformed(MainFrame.java:498)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)[/WR]
Hier ist die Dialogklasse, ist leider schon etwas unübersichtlich geworden, der Fehler scheint im Konstruktor bei der Initialisierung sp1 und sp2 zu sein.
Java:
package main;
import javax.crypto.KeyGenerator;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.filechooser.FileFilter;
import main.FileHandler.CryptType;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.lang.reflect.Array;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
public class KeyDialog extends JDialog{
JComboBox keyGenCombo;
String val="AES";
String keySize;
JTextField targetField;
String writeFile="C:/";
String persKey;
JButton keyIn;
JCheckBox writeCheck;
boolean auto=true;
boolean keyInFile=true;
JTextArea pubKeyField,priKeyField;
KeyDialog kd;
JPanel p2,p3,p1,p4;
JLabel p3Label;
JScrollPane sp1,sp2;
public KeyDialog(JFrame parent,Point point) {
super();
kd=this;
CryptType[] cTypes=FileHandler.CryptType.values();
String[] values = new String[cTypes.length];
for(int i=0;i<cTypes.length;i++){
values[i]=cTypes[i].name();
}
Image icon=new ImageIcon("Pictures/key.png").getImage();
setModal(true);
setLocation(point.x-20,point.y-20);
setTitle("Key-Erstellungsdialog");
setSize(600,240);
setIconImage(icon);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
p1=new JPanel();
p1.setLayout(new GridLayout(4, 2,15,15));
JLabel comLab=new JLabel("Schlüsselart:",JLabel.RIGHT);
keyGenCombo=new JComboBox<>(values);
keyGenCombo.addActionListener(auswählen);
p1.add(comLab);
p1.add(keyGenCombo);
p1.add(new JLabel());
writeCheck=new JCheckBox();
writeCheck.setLabel("Schlüssel in Datei scheiben");
writeCheck.addActionListener(writeCheckListener);
p1.add(writeCheck);
writeCheck.setSelected(true);
targetField=new JTextField();
targetField.setText("Wählen sie einen Zielpfad");
targetField.setPreferredSize(new Dimension(300, 30));
targetField.setToolTipText(targetField.getText());
targetField.setEditable(false);
p1.add(targetField);
ImageIcon pathIco=new ImageIcon("Pictures/folder.png");
JButton setPathButton=new JButton(pathIco);
setPathButton.addActionListener(zielWählen);
setPathButton.setToolTipText("Wählen sie den Zielpfad für ihre/n Schlüssel");
p1.add(setPathButton);
JButton runButton=new JButton("Schlüssel erstellen");
runButton.addActionListener(runAction);
p1.add(runButton);
JButton abortButton=new JButton("Abbrechen");
abortButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
KeyDialog.this.setVisible(false);
KeyDialog.this.dispose();
}
});
p1.add(abortButton);
add(p1,BorderLayout.NORTH);
//Panel mit dem JTextField für den Key/PublicKey
p3=new JPanel();
p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
p3.setBorder(new LineBorder(Color.BLACK, 1));
p3Label=new JLabel("Key",new ImageIcon("Pictures/keySmall.png"),JLabel.CENTER);
p3.add(p3Label);
pubKeyField=new JTextArea();
pubKeyField.setLineWrap(true);
pubKeyField.setSize(250,75);
pubKeyField.setEditable(false);
p3.add(pubKeyField);
sp1=new JScrollPane(p3, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
//Panel mit dem JTextField für den PrivateKey
p4=new JPanel();
p4.setLayout(new BoxLayout(p4, BoxLayout.Y_AXIS));
p4.setBorder(new LineBorder(Color.BLACK, 1));
p4.add(new JLabel("Private Key:",new ImageIcon("Pictures/keySmall.png"),JLabel.CENTER));
priKeyField=new JTextArea();
priKeyField.setLineWrap(true);
priKeyField.setEditable(false);
//sp2=new JScrollPane(priKeyField, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
p4.add(priKeyField);
sp2=new JScrollPane(p4, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
p2=new JPanel();
p2.setLayout(new BoxLayout(p2,BoxLayout.X_AXIS));
p2.add(sp1);
p2.add(sp2);
add(p2,BorderLayout.CENTER);
p2.disable();
p2.setVisible(false);
setVisible(true);
}
ActionListener runAction=new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
Key[] key = generateKey(val);
if(key != null)
{
if(keyInFile)
writeKeyToFile(key);
//TODO Der Key muss mit einem Label ausgegeben werden
removeKeyFields();
setKeyFields(val);
switch(key.length)
{
case 1:
String keyString = Tools.getHexString(key[0].getEncoded());
System.out.println("Der generierte "+val+" Schlüssel lautet (hexadezimal): "+keyString);
pubKeyField.setText(keyString);
break;
case 2:
String publicString = Tools.getHexString(key[0].getEncoded());
String privateString = Tools.getHexString(key[1].getEncoded());
System.out.println("Das generierte "+val+" Schlüsselpaar lautet (hexadezimal):");
System.out.println("Public Key: "+publicString);
System.out.println("Private Key: "+privateString);
pubKeyField.setText(publicString);
priKeyField.setText(privateString);
break;
}
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
};
private Key[] generateKey(String type) throws Exception
{
Key[] key = null;
switch (type) {
case "RSA":
KeyPairGenerator pairgen = KeyPairGenerator
.getInstance("RSA");
SecureRandom secRand = new SecureRandom();
pairgen.initialize(2048, secRand);
KeyPair keyPair = pairgen.generateKeyPair();
key = new Key[]{keyPair.getPublic(), keyPair.getPrivate()};
break;
case "AES":
case "DES":
KeyGenerator keygen = KeyGenerator.getInstance(val);
SecureRandom random = new SecureRandom();
keygen.init(random);
key = new Key[]{keygen.generateKey()};
break;
}
return key;
}
private void writeKeyToFile(Key[] key) throws Exception
{
if(key != null)
{
FileOutputStream out;
switch(key.length){
case 1:
out = new FileOutputStream(new File(writeFile+"/"+val+".key"));
out.write(Tools.getHexString(key[0].getEncoded()).getBytes());
out.flush();
out.close();
break;
case 2:
//public
out = new FileOutputStream(new File(writeFile+"/"+val+"_public.key"));
out.write(Tools.getHexString(key[0].getEncoded()).getBytes());
out.flush();
out.close();
//private
out = new FileOutputStream(new File(writeFile+"/"+val+"_private.key"));
out.write(Tools.getHexString(key[1].getEncoded()).getBytes());
out.flush();
out.close();
break;
}
}
}
ActionListener auswählen=new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
val=keyGenCombo.getSelectedItem().toString();
System.out.println(val);
}
};
ActionListener zielWählen=new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser jfc=new JFileChooser();
jfc.addChoosableFileFilter(new KeyFileFilter());
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
try{
jfc.setCurrentDirectory(new File(MainFrame.writeFile));
}catch(Exception ex){
}
int returnVal=jfc.showDialog(rootPane, "Wählen sie den Schlüssel-Zielpfad");
if (returnVal == JFileChooser.APPROVE_OPTION) {
writeFile = jfc.getSelectedFile().getAbsolutePath();
targetField.setText(jfc.getSelectedFile().getAbsolutePath());
}
}
};
public class KeyFileFilter extends FileFilter{
@Override
public boolean accept(File f) {
// TODO Auto-generated method stub
return (f.isDirectory()||
f.getName().toLowerCase().endsWith(".key"));
}
@Override
public String getDescription() {
// TODO Auto-generated method stub
return "Schlüsseldateien mit der Endung .key";
}
}
ActionListener writeCheckListener=new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(writeCheck.isSelected()){
keyInFile=true;
}else{
keyInFile=false;
}
}
};
public void setKeyFields(String type){
switch(type)
{
case "RSA":
setDoubleField();
break;
default:
setLoneField();
}
//kd.setSize(500, 400);
kd.p2.enable();
kd.p2.setVisible(true);
kd.p1.validate();
kd.p2.validate();
}
public void removeKeyFields(){
kd.setSize(500, 240);
kd.p2.disable();
kd.p2.setVisible(false);
kd.p1.validate();
}
public void setDoubleField(){
p2=new JPanel(new GridLayout(1,2));
p2.add(p3);
p2.add(p4);
kd.add(p2,BorderLayout.CENTER);
sp1.setVisible(true);
sp2.setVisible(true);
p3Label.setText("Public Key");
p2.validate();
p2.setVisible(true);
priKeyField.setText("");
pubKeyField.setText("");
kd.pack();
kd.setSize(600, 600);
}public void setLoneField(){
p2=new JPanel(new GridLayout(1,1));
p2.add(sp1);
p3Label.setText("Key");
kd.add(p2,BorderLayout.CENTER);
p2.validate();
p2.setVisible(true);
priKeyField.setText("");
pubKeyField.setText("");
kd.pack();
kd.setSize(600, 400);
}
}