Pessoal, estou montando uma aplicação, e após criar um arquivo, quero apenas mostrar uma telinha avisando ao usuário que o arquivo foi criado.
estou usando o código mais simples
JOptionPane.showMessageDialog(null, "Mensagem");
Acontece que a janelinha aparece apenas com o botão OK, porém nem a String “Mensagem” nem o icone (que seria aquele de informacao) aparecem.
Fiz um teste criando direto na main e funcioanou normal, mas quando uso no código o negócio não vai de jeito nenhum.
Acho que é algum problema nos métodos que desenham a janela.
Alguém tem alguma idéia de como posso resolver?
ps:anexei uma imagem para verem como está aparecendo
Desde ja agradeço

é kra não sei não
aqui no meu PC funciona normalmente em quaquer lugar q eu coloque o JOptionPane.
tenta adicionar os outros parametros do dialog, exemplo:
o ultimo parametro é o tipo de icone, o penultimo parametro é o titulo da janela…
-1 : sem icone
1 : icone de informação normal
2 : icone de warning
ou
JOptionPane.ERROR_MESSAGE
JOptionPane.INFORMATION_MESSAGE
JOptionPane.DEFAULT_OPTION
entre outros
Não vai resolver o problema anterior, pois dos jeito que tava era pra funcionar, mas talvez quebre um galho.
ja tentei mudar o construtor e nada… O problema parece ser na classe que desenha os botões …
Será que alguem sabe como pelo menos testar isso? :?
Tem como vc mandar mais partes do codigo? Aqui também eu testei e funcionou perfeitamente.
fiz um teste que pode ajudar a resolver o problema…
o erro só acontece quando eu crio o JOptionPane depois de setar o JFrame.setVisible(true)
quando eu crio antes o JOptionPane aparece certinho.
é kra manda mais partes do seu codigo, pq aqui funciona independentemente de setvisible() ou qqer outro meotod
Ai vai o codigo completo
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
public class Screen extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JButton btnExportToPDF, btnSearch, btnExportToExcel;
private JComboBox jcbList;
private JTextField jtfSearch;
private JPanel pSearchType;
private void create() {
// Creating Server Info Panel
JPanel pServerInfo = new JPanel(new FlowLayout());
pServerInfo.setPreferredSize(new Dimension(280, 130));
pServerInfo.setBorder(BorderFactory
.createTitledBorder("Server Information"));
// Creating Labels and Text Fields for Server Info Panel
JLabel lHostname = new JLabel("Host Name");
lHostname.setPreferredSize(new Dimension(70, 27));
JTextField jtfHostname = new JTextField();
jtfHostname.setPreferredSize(new Dimension(140, 27));
JLabel lUser = new JLabel("User");
lUser.setPreferredSize(new Dimension(70, 27));
JTextField jtfUser = new JTextField();
jtfUser.setPreferredSize(new Dimension(140, 27));
JLabel lPassword = new JLabel("Password");
lPassword.setPreferredSize(new Dimension(70, 27));
JTextField jtfPassword = new JTextField();
jtfPassword.setPreferredSize(new Dimension(140, 27));
// Adding Itens to Panel
pServerInfo.add(lHostname);
pServerInfo.add(jtfHostname);
pServerInfo.add(lUser);
pServerInfo.add(jtfUser);
pServerInfo.add(lPassword);
pServerInfo.add(jtfPassword);
// End of Server Info Panel
// Search Type Panel
pSearchType = new JPanel(new FlowLayout(FlowLayout.RIGHT, 30, 15));
pSearchType.setPreferredSize(new Dimension(330, 130));
pSearchType.setBorder(BorderFactory.createTitledBorder("Search Type"));
// Creating Combo Box
jcbList = new JComboBox();
jcbList.addItem("Name");
jcbList.addItem("E-mail");
jcbList.addItem("UID");
jcbList.setPreferredSize(new Dimension(100, 26));
// Creating the text field
jtfSearch = new JTextField();
jtfSearch.setPreferredSize(new Dimension(140, 27));
jtfSearch.setText("Enter NAME here");
jtfSearch.getFocusAccelerator();
jtfSearch.selectAll();
// Creating Search Button
btnSearch = new JButton("Search");
btnSearch.setPreferredSize(new Dimension(270, 30));
// Adding Itens to Search Type Panel
pSearchType.add(jcbList);
pSearchType.add(jtfSearch);
pSearchType.add(btnSearch);
// End of Search Type Panel
// Creating Options Pane
JPanel pOptions = new JPanel(new FlowLayout());
pOptions.setPreferredSize(new Dimension(615, 60));
pOptions.setBorder(BorderFactory.createTitledBorder("Options"));
// Creating PDF Button
btnExportToPDF = new JButton("Export to PDF");
btnExportToPDF.setPreferredSize(new Dimension(150, 20));
// Creating Excel Button
btnExportToExcel = new JButton("Export to Excel");
btnExportToExcel.setPreferredSize(new Dimension(120, 20));
// Adding Listeners to buttons and Combo box
// the managers methods will handle the actions
btnExportToExcel.addActionListener(buttonManager);
btnExportToPDF.addActionListener(buttonManager);
jcbList.addActionListener(comboManager);
// Adding Button to Options Pane
pOptions.add(btnExportToPDF);
pOptions.add(btnExportToExcel);
// End of Option Pane
// Creating Information Panel
// This Panel contains the table with all information
// Creating a new table calling the TableCreator Method
TableCreator table = new TableCreator();
// Creating the Panel and adding the table
// the create method return the populated and formated table
JScrollPane pInformation = new JScrollPane(table.create());
pInformation.setPreferredSize(new Dimension(615, 350));
// End of Information Panel
// Setting some screen configurations
this.setLayout(new FlowLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("LSE - LDAP Search Engine");
this.setSize(650, 600);
this.setResizable(false);
this.setLocationRelativeTo(null);
// Adding Panes to JFrame
// If you change the sequence that the panels are added
// it will affect the screen
this.getContentPane().add(pServerInfo);
this.getContentPane().add(pSearchType);
this.getContentPane().add(pOptions);
this.getContentPane().add(pInformation);
}
private ActionListener buttonManager = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnExportToExcel) {
ExcelCreator execelCreator = new ExcelCreator();
execelCreator.print();
JOptionPane.showMessageDialog(null,"Mensagem","(Título da mensagem)",JOptionPane.INFORMATION_MESSAGE);
} else if (e.getSource() == btnExportToPDF) {
PDFCreator pdfCreator = new PDFCreator();
pdfCreator.print();
JOptionPane.showMessageDialog(null,"Mensagem","(Título da mensagem)",JOptionPane.INFORMATION_MESSAGE);
}
};
};
private ActionListener comboManager = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (jcbList.getSelectedIndex() == 0)
jtfSearch.setText("Enter NAME here");
else if (jcbList.getSelectedIndex() == 1)
jtfSearch.setText("Enter E-MAIL here");
else if (jcbList.getSelectedIndex() == 2)
jtfSearch.setText("Enter UID here");
jtfSearch.selectAll();
};
};
void Show(){
JOptionPane.showMessageDialog(null,"Mensagem","(Título da mensagem)",JOptionPane.INFORMATION_MESSAGE);
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
Screen Screen = new Screen();
Screen.create();
Screen.setVisible(true);
}
}
Tenho quase certeza que eçe não esta conseguindo desenhar por algum motivo… note tambem que se você ficar mexendo a janelinha que abre, ele vai “apagando” a tela do fundo…
Pessoal, descobri onde está o erro. Só não sei como resolver… vamos lá…
O erro acontece quando eu adiciono o JScroolPane … esse JScroolPane tem uma tabela dentro…
ta dando algum pau porque ele desenha a tabela e depois nao consegue desenhar os botoes em cima…
podem fazer o teste… c tirar a linha q inclui o `jscroolpane ele funciona certinho
como eu resolvo isso? 
kra teste sua classe e funcionou corretamente, inclusive não foi apagando nada qdo eu fiquei mexendo na janela, axu q o problema eh com seu computador.
mas se vc esta falando q esta apagando o fundo, deve ser algum problema com a sua classe ExcelCreator e PDFCreator. pq aki naum usei els pra testar e funcionou, tenta lançar um thread para cada uma das duas classes.
Bacana,
seu código funcionou.
Sem problemas, mesmo com o scrollpane.
Tá estranho mesmo.
consegui chegar um pouco mais longe.
na classe TableCreator, eu sobrescrevo o metodo getTableCellRendererComponent, para as linhas ficarem coloridas…
é exatamente ai, pois qdo eu comentei o metodo sobrescrito e deixei a tabela normalzinha, funcionou certinho… ai vai o codigo da tablecreator pra vcs verem que eu nao estou ficando louco =D
import java.awt.Color;
import java.awt.Component;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
/**
* @author Ronald Tetsuo Miura
*/
public class TableCreator extends DefaultTableCellRenderer {
/** */
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
* java.lang.Object, boolean, boolean, int, int)
*/
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
String s = table.getModel().getValueAt(row, 2).toString();
if (s == "") {
c.setBackground(Color.red);
table.setValueAt("FAIL", row, 3);
} else
c.setBackground(null);
return c;
}
/**
* @param args
*/
public JTable create() {
Vector header = new Vector();
header.add("ID");
header.add("Field");
header.add("Value");
header.add("Status");
Vector data = new Vector();
Vector<String> row = new Vector();
row.add("l1c1");
row.add("l1c2");
row.add("");
row.add("Fail");
Vector<String> row2 = new Vector();
row2.add("");
row2.add("");
row2.add("");
row2.add("l2c4");
Vector row3 = new Vector();
row3.add("Teste1fwfwfwfwfwfwfwfwfwfwfwfwfw");
row3.add("Teste2");
row3.add("ff");
row3.add("Teste4");
data.add(row);
data.add(row2);
data.add(row3);
JTable table = new JTable(new DefaultTableModel(data, header));
//table.setDefaultRenderer(Object.class, new TableCreator());
table.setEnabled(false);
return table;
}
}
Pessoal, consegui resolver o problema.
quando eu sobrescrevia a classe getDefaultTableCellRenderer, eu deixava uma celulaX com fundo vermelho, e setava seu valor para “FAIL”.
Acontece que pra setar esse valor o Java desenha um JLabel em cima da celula e deixa la (estranho, mais eh assim que o java desenha celula)… ai acho que dava algum “choque” na hora de desenhar o JOptionPane.
Resumindo, eu soh tirei a linha table.setValueAt(“FAIL”, row, 3);
do metodo getDefaultTableCellRenderer da classe TableCreator…
Ufa!
vlw ai pela força galera.