Buscar
Social
Ofertas laborales ES

Foro sobre Java SE > Ayuda con JPanel

Hola muchachos, como les va?...
estoy teniendo un problemita con un menu de mi soft, lo que el menu hace especificamente es crear un nuevo JFrame en el cual muestra una cierta cantidad de información, tiene dos botones que son previous y next que avanzan y regresan distinta información...
esto funciona, el problema esta en que cada vez que yo presiono cualquier boton sea previous o next me crea un nuevo JFrame, ¿cual será el problema?. acá les dejo el código para que chequeen. desde ya gracias.

Edit.add(Develop);
this.Develop.setEnabled(true);
Develop.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
KSTool.this.displayDeveloperMenu();
}
}
);

private void displayDeveloperMenu()
{
JFrame develop = new JFrame("Developer");
develop.setResizable(true);
develop.setBounds(450,200,650,400);

this.myWaveform.readWaveformDescription(this.metaImgFilepath,
this.myHeader.getNbMultisample(),
this.myHeader.getNbMultisampleDescription(),
this.currentWaveform);

this.title4.setText(String.valueOf(this.currentWaveform));
this.sampleName.setText(this.myWaveform.getSampleName());
this.loopF.setText(String.valueOf(myWaveform.getLoop()));
this.compressA.setText(String.valueOf(myWaveform.getCompressCoefA()));
this.compressB.setText(String.valueOf(myWaveform.getCompressCoefB()));
this.sStartF.setText(String.valueOf(myWaveform.getSampleStart()));
this.sStart2.setText(String.valueOf(myWaveform.getSampleStart2()));
this.loopF.setText(String.valueOf(myWaveform.getLoopStart()));
this.loopEndF.setText(String.valueOf(myWaveform.getLoopEnd()));
this.rEndF.setText(String.valueOf(myWaveform.getReverseEnd()));
this.thirdAddresF.setText(String.valueOf(myWaveform.getThirdToNine()));
this.unknownF.setText(String.valueOf(myWaveform.getUnknown4()));
this.addCoefF.setText(String.valueOf(myWaveform.getUnknown5()));
this.rEnd2F.setText(String.valueOf(myWaveform.getUnknown6()));
this.rEnd3F.setText(String.valueOf(myWaveform.getUnknown7()));
this.unknown2F.setText(String.valueOf(myWaveform.getUnknown8()));
this.addCoefBF.setText(String.valueOf(myWaveform.getUnknown9()));
this.addStartF.setText(String.valueOf(myWaveform.getUnknown10()));
this.addsSizeF.setText(String.valueOf(myWaveform.getUnknown11()));
this.sSizeF.setText(String.valueOf(myWaveform.getSampleSizeX2()));

develop.getContentPane().setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();

gbc.fill = 0;
gbc.anchor = 512;

gbc.gridx = 0;
gbc.gridy = 0;
develop.getContentPane().add(wave, gbc);
gbc.gridx = 1;
gbc.gridy = 0;
develop.getContentPane().add(title4, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
develop.getContentPane().add(sname,gbc);
gbc.gridx = 1;
gbc.gridy = 1;
gbc.weightx = 1.0D;
this.sampleName.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(sampleName,gbc);
gbc.gridx = 0;
gbc.gridy = 2;
develop.getContentPane().add(Loop,gbc);
gbc.gridx = 1;
gbc.gridy = 2;
this.loopF.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(loopF,gbc);
gbc.gridx = 0;
gbc.gridy = 3;
develop.getContentPane().add(cA,gbc);
gbc.gridx = 1;
gbc.gridy = 3;
this.compressA.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(compressA,gbc);
gbc.gridx = 0;
gbc.gridy = 4;
develop.getContentPane().add(cB,gbc);
gbc.gridx = 1;
gbc.gridy = 4;
this.compressB.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(compressB,gbc);
gbc.gridx = 0;
gbc.gridy = 5;
develop.getContentPane().add(sampleStart,gbc);
gbc.gridx = 1;
gbc.gridy = 5;
this.sStartF.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(sStartF,gbc);
gbc.gridx = 0;
gbc.gridy = 6;
develop.getContentPane().add(sampleStart2,gbc);
gbc.gridx = 1;
gbc.gridy = 6;
this.sStart2.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(sStart2,gbc);
gbc.gridx = 0;
gbc.gridy = 7;
develop.getContentPane().add(loopStart,gbc);
gbc.gridx = 1;
gbc.gridy = 7;
this.loopF.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(loopF,gbc);
gbc.gridx = 0;
gbc.gridy = 8;
develop.getContentPane().add(loopEnd,gbc);
gbc.gridx = 1;
gbc.gridy = 8;
this.loopEndF.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(loopEndF,gbc);
gbc.gridx = 0;
gbc.gridy = 9;
develop.getContentPane().add(rEnd,gbc);
gbc.gridx = 1;
gbc.gridy = 9;
this.rEndF.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(rEndF,gbc);
gbc.gridx = 0;
gbc.gridy = 10;
develop.getContentPane().add(thirdAddress,gbc);
gbc.gridx = 1;
gbc.gridy = 10;
this.thirdAddresF.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(thirdAddresF,gbc);
gbc.gridx = 0;
gbc.gridy = 11;
develop.getContentPane().add(unknown,gbc);
gbc.gridx = 1;
gbc.gridy = 11;
this.unknownF.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(unknownF,gbc);
gbc.gridx = 0;
gbc.gridy = 12;
develop.getContentPane().add(addCoef,gbc);
gbc.gridx = 1;
gbc.gridy = 12;
this.addCoefF.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(addCoefF,gbc);
gbc.gridx = 0;
gbc.gridy = 13;
develop.getContentPane().add(rEnd2,gbc);
gbc.gridx = 1;
gbc.gridy = 13;
this.rEnd2F.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(rEnd2F,gbc);
gbc.gridx = 0;
gbc.gridy = 14;
develop.getContentPane().add(rEnd3,gbc);
gbc.gridx = 1;
gbc.gridy = 14;
this.rEnd3F.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(rEnd3F,gbc);
gbc.gridx = 0;
gbc.gridy = 15;
develop.getContentPane().add(unknown2,gbc);
gbc.gridx = 1;
gbc.gridy = 15;
this.unknown2F.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(unknown2F,gbc);
gbc.gridx = 0;
gbc.gridy = 16;
develop.getContentPane().add(addCoefB,gbc);
gbc.gridx = 1;
gbc.gridy = 16;
this.addCoefBF.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(addCoefBF,gbc);
gbc.gridx = 0;
gbc.gridy = 17;
develop.getContentPane().add(sStart,gbc);
gbc.gridx = 1;
gbc.gridy = 17;
this.addStartF.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(addStartF,gbc);
gbc.gridx = 0;
gbc.gridy = 18;
develop.getContentPane().add(addsSize,gbc);
gbc.gridx = 1;
gbc.gridy = 18;
this.addsSizeF.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(addsSizeF,gbc);
gbc.gridx = 0;
gbc.gridy = 19;
develop.getContentPane().add(sSize,gbc);
gbc.gridx = 1;
gbc.gridy = 19;
this.sSizeF.setPreferredSize(new Dimension(200, 25));
develop.getContentPane().add(sSizeF,gbc);
gbc.gridx = 0;
gbc.gridy = 20;
develop.getContentPane().add(buttonPreviousWF, gbc);
gbc.gridx = 2;
gbc.gridy = 20;
develop.getContentPane().add(this.buttonNextWF, gbc);

develop.getContentPane().revalidate();
develop.repaint();

develop.pack();
develop.setVisible(true);
}

septiembre 23, 2014 | Registered Commenternewstyl3

Te lo crea porque cada vez que ejecutas el método displayDeveloperMenu()
este línea JFrame develop = new JFrame("Developer"); crea uno nuevo.

septiembre 23, 2014 | Registered Commenterchoces

gracias @choces ya lo solucione. saque el JFrame develop = new JFrame("Developer");
del displayDeveloperMenu() y ya me funciona... ahora necesito otra ayudita, en mi programa tengo un JTree que muestra los ficheros abiertos. tengo un menu Clear All que borra todo, el tema es que si yo utilizo este menu efectivamente borra todo pero si cargo otro archivo me mantiene los nombres de los anteriores siempre.. aca te dejo el código.

public KSTool() {
super("Korg Sample Tools V0.6.9");
setDefaultCloseOperation(3);
setBounds(350, 100, 800, 650);
try
{
this.myPicture = ImageIO.read(getClass().getResource("icono ks.png"));
}
catch (IOException e)
{
e.printStackTrace();
}
this.picLabel = new JLabel(new ImageIcon(this.myPicture));

//New Tree
instrumentTree = new JTree();
waveTree = new JTree();

displayTree();

instrumentTree.setEditable(true);
instrumentTree.setPreferredSize(null);

setJMenuBar(menuBar);

menuBar.add(File);
File.add(openFile);
File.add(jSeparator1);
File.add(saveFile);
this.saveFile.setEnabled(false);
File.add(saveCollection);
this.saveCollection.setEnabled(false);
File.add(jSeparator2);
File.add(clearAll);
File.add(recentFiles);
File.add(jSeparator3);
File.add(exitMenu);

openFile.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0)
{
JFileChooser fileChooser = new JFileChooser();
fileChooser.setAcceptAllFileFilterUsed(false);
//Filtros JFileChooser
FileNameExtensionFilter metaKrome = new FileNameExtensionFilter("META.IMG V1 Krome", "IMG");
fileChooser.addChoosableFileFilter(metaKrome);

int returnVal = fileChooser.showOpenDialog(null);
if (returnVal == 0)
{
//FILECHOOSER FILTRO META.IMG KROME:
KSTool.this.metaImgFilepath = fileChooser.getSelectedFile().getPath();
String MetaName = fileChooser.getSelectedFile().getName();
String opc1 = "META.IMG";
KSTool.this.myHeader.readMetaFileHeader(KSTool.this.metaImgFilepath);


if (KSTool.this.myHeader.getIdKorg() != null && KSTool.this.myHeader.getVersion() == 0x30303031)
{
System.out.println("Open META.IMG Krome File access granted.");
System.out.println("Loaded " + KSTool.this.myHeader.getNbMultisample() + " Instrumens and " + KSTool.this.myHeader.getNbWaveformDescription() + " Waveforms Samples.");
KSTool.this.currentMultisample = 0;
KSTool.this.currentMultisampleDescription = 0;
KSTool.this.currentWaveform = 0;
System.out.println("Instruments Samples correctly loaded");

KSTool.this.saveFile.setEnabled(true);
KSTool.this.saveCollection.setEnabled(true);
System.out.println("Save Menus Activated");
KSTool.this.Develop.setEnabled(true);
System.out.println("Developer Menu Activated");
KSTool.this.runWaveform.setEnabled(true);
System.out.println("Run Waveform Menu Activated");
KSTool.this.appProperties.setEnabled(true);
System.out.println("View - Properties Menu Activated");
KSTool.this.playAudio.setEnabled(true);
System.out.println("View - Play Audio Menu Activated");
System.out.println("*****************************************");

//Crea el nombre del archivo .ksc
//KSTool.this.treeNode = new DefaultMutableTreeNode();
//Instruments and layers
int bank = 0;
int nbProgram = 0;
int nbLayer = 0;
for(
KSTool.this.currentMultisample = 0;
KSTool.this.currentMultisample != KSTool.this.myHeader.getNbMultisample();
KSTool.this.currentMultisample++)
{
myMultisampleInfo.readMultisampleInfo(KSTool.this.metaImgFilepath,
KSTool.this.currentMultisample);
//Creacion de Nodo Instrument:
instrumentNode = new DefaultMutableTreeNode(bank + " : " + nbLayer + " : " + nbProgram++ + " : " +
(KSTool.this.myMultisampleInfo.getMultisampleName()));
collection.add(instrumentNode);

System.out.println("Instrument: " + (KSTool.this.myMultisampleInfo.getMultisampleName()) + " correctly loaded");}
System.out.println("*****************************************");

//Waveforms
for(KSTool.this.currentWaveform = 0;KSTool.this.currentWaveform != KSTool.this.myHeader.getNbWaveformDescription() ;KSTool.this.currentWaveform++)
{
myWaveform.readWaveformDescription(KSTool.this.metaImgFilepath,
KSTool.this.myHeader.getNbMultisample(),
myHeader.getNbMultisampleDescription(),
currentWaveform);

//Creacion de Nodo Waveform:
int nbSamples = 0;
waveformListNode = new DefaultMutableTreeNode (
myWaveform.getSampleName()
);
wave2.add(waveformListNode);
System.out.println("*****************************************");

}

KSTool.this.repaint();

}
else
{
frame = new JFrame("File access canceled by user");

JOptionPane.showMessageDialog(frame,
"File access cancelled by user.",
"Attention",
JOptionPane.INFORMATION_MESSAGE);
}
}});

clearAll.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
collection.removeAllChildren();
wave2.removeAllChildren();

currentMultisample = 0;
currentMultisampleDescription = 0;
currentWaveform = 0;
currentKSF = 0;
currentKMP = 0;
currentKSC = 0;
currentRAW = 0;
currentLoop = 0;
KSTool.this.saveFile.setEnabled(false);
KSTool.this.saveCollection.setEnabled(false);
wave2Temp = null;
metaImgFilepath = null;
sampleKscFilepath = null;
sampleKmpFilepath = null;
tempFilepath = null;
sampleKsfFilepath = null;
sampleKsfSavepath = null;
outputKsfFilepath = null;
outputMetaFilepath = null;
outputSampleFilePath = null;
Develop.setEnabled(false);
}
});
}

private void displayTree()
{
//Node
collection = new DefaultMutableTreeNode("Collection");
DefaultTreeModel collectionModel = new DefaultTreeModel(collection);

wave2 = new DefaultMutableTreeNode("Waveforms");
DefaultTreeModel wave2Model = new DefaultTreeModel(wave2);

instrumentTree = new JTree(collectionModel);
waveTree = new JTree(wave2Model);

sp2 = new JScrollPane(instrumentTree);
sp3 = new JScrollPane(waveTree);

add(sp2,BorderLayout.WEST);
add(sp3,BorderLayout.CENTER);
}

septiembre 24, 2014 | Registered Commenternewstyl3

Con este código, que no es compilable ni ejecutable, solo puedo hacer suposiciones.
No veo la necesidad de crear nuevos JTree en el método displayTree(), como tampoco veo cuál es el JTree que sigue mostrando lo que no debería.

septiembre 25, 2014 | Registered Commenterchoces

gracias @choces por responder siempre... lo pude resolver, solo reordene todo el código por que era un desastre y funciono :)

septiembre 25, 2014 | Registered Commenternewstyl3