You are being forwarded to the lastest updates ot his page!
Or you can Click Here if it doesn't work or you don't wish to wait.

JOptionPane and Unicode characters

Glen Tanner
I am trying to get tabs to display in a JOptionPane. Does anyone know of a workaround to get the JOptionPane to recognize special characters? (I've also tried using Unicode chars without any luck.)
The pane displays a tab as square box.

Any help would be appreciated!!

Glen

Here's a sample:

import javax.swing.JOptionPane;


public class TestChar
{
static String temp2 = new String("test" + '\t' + "test");

public static void main(String[] args)
{
System.out.println(temp2);
JOptionPane.showMessageDialog(null,temp2,"Title",JOptionPane.INFORMATION_MESSAGE);
}
}


[This message has been edited by Glen Tanner (edited February 03, 2000).]

[This message has been edited by Glen Tanner (edited February 03, 2000).]


Frank Carver
A workaround would be to substitute tabs in the input text for spaces yourself. For example:

code:

import javax.swing.JOptionPane;

public class TestChar
{
static String temp2 = "test\ttest";

private static String expandTabs(String in)
{
StringBuffer buf = new StringBuffer(in);
int len = buf.length();

// count down to avoid stepping on recently inserted chars
for (int i = len-1; i >= 0; --i)
{
if (buf.charAt(i) == '\t')
{
buf.setCharAt(i, ' ');
// insert seven more spaces, or you could put just the number to
// the next tab stop if you prefer
buf.insert(i, " ");
}
}

return buf.toString();
}

public static void main(String[] args)
{
System.out.println(temp2);
JOptionPane.showMessageDialog(null,expandTabs(temp2),"Title",JOptionPane.INFORMATION_MESSAGE);
}
}


Is that the kind of thing you were looking for?