adding html to joptionpane or dialog?
Hi there, I have these two string arrays... one with sucessfull connections and another with failed connections. i want to display them in a joption pane or dialog listed like so:
connection1 Success (in Green)
connection2 Sucess
connection 3 Failure (in Red)
String failsedsockets]=[Socket[addr=dbappsrv-11/167.192.14.11,port=8109,localport=4563]
String addressockets[] =[Socket[addr=dbappsrv-06/167.192.13.10,port=8109,localport=9874]]
JOptionPane.showMessageDialog(null,"Success: \n"+addressockets+"\n\n Failed:\n"+failedsockets,"Quaestor Result", JOptionPane.PLAIN_MESSAGE);
one or the ways
import javax.swing.*;
class Testing
{
public static void main(String[] args)
{
JLabel success = new JLabel("Success");
success.setForeground(java.awt.Color.GREEN);
JLabel failure = new JLabel("Failure");
failure.setForeground(java.awt.Color.RED);
JPanel p = new JPanel(new java.awt.GridLayout(2,1));
p.add(success); p.add(failure);
JOptionPane.showMessageDialog(null,p);
System.exit(0);
}
}
I think the question is more thisL I want to add a string and jlabel to a jpane.
jpane.add(string,jlabel) then call it in
JOptionPane.showMessageDialog(null,jpane," Result", JOptionPane.PLAIN_MESSAGE);?
I was trying to do that but it doesnt display the string?
ublic static void main(String[] args)
{
JLabel success = new JLabel("Success");
success.setForeground(java.awt.Color.GREEN);
JLabel failure = new JLabel("Failure");
failure.setForeground(java.awt.Color.RED);
JPanel p = new JPanel(new java.awt.GridLayout(2,2));
String printout="dbav-05";
String another="blah"
p.add(printout,failure);
p.add(another,success);
JOptionPane.showMessageDialog(null, p,"Quaestor Result", JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
Sorry after much code looking I didn't realize what I was writing... well what I want to do is printout the success and failures of the connection in a joption pane with success in green and failure in red. write now my code just prints it out a string with successes and failures in black... here is my code
static JLabel works=new JLabel("<html><font color='green'>Success</font></html>");
static JLabel fails=new JLabel("<html><font color='red'>Fail</font></html>");
private static Properties loadProperties(String filename) {
Properties props=new Properties();
try {
props.load(new FileInputStream(filename));
} catch(FileNotFoundException fnfe) {
System.out.println("Can not find "+filename);
fnfe.printStackTrace();
} catch (IOException ioe) {
System.out.println("Problem loading "+filename);
ioe.printStackTrace();
}
return props;
}
public static void Build() throws IOException{
Properties props;
Socket quaestor=null;
props = loadProperties("quaestor.ini");
String invokeit=props.getProperty("Command");
ArrayList <Socket> listofsockets=new ArrayList <Socket>();
ArrayList <String> failedsockets=new ArrayList <String>();
//ArrayList <String> addressockets=new ArrayList <String>();
String[] splitvals= props.getProperty("Quaestors").split(" ");
String printout ="";
for (int i=0; i<splitvals.length; i++){
String[] temp=splitvals[i].split(":");
String host=temp[0];
int port=Integer.parseInt(temp[1]);
try{
quaestor=new Socket(host,port);
listofsockets.add(quaestor);
printout+=quaestor.getInetAddress().getHostName()+" Success\n";
}
catch (UnknownHostException e) {
failedsockets.add(temp[0]);
printout+=temp[0]+"Fail\n";
System.err.println("Not known host. "+ failedsockets);
e.printStackTrace();
} catch (IOException e) {
failedsockets.add(temp[0]);
printout+=temp[0]+"Fail\n";
System.err.println("Couldn't get I/O for " + "the connection: "+failedsockets);
e.printStackTrace();
}
}
System.out.println(failedsockets + "fail");
System.out.println(listofsockets+ "works");
//System.out.println(printout);
JOptionPane.showMessageDialog(null,printout,"Quaestor Result", JOptionPane.PLAIN_MESSAGE);
}
public static void main (String[] args) throws IOException{
Build();
}
Sorry for putting in the wrong area , it went from a java programming question to a swing one. w/o thinking i didnt post it in the right place... .. saw the link below about the joption pane but it didnt really clear up much for me. maybe if ilook at it today..i can figure something out. much help appreciated.>