Reputation: 21
Above image shows a rectangle which is in between time-value and am, In Java21.0.3, DateTime string has a character NNBSP which is converting to rectangle while painting it.
Following code illustrates the issue:
public class RunningStringPanel extends JPanel implements ActionListener {
private String text;
public RunningStringPanel(String text, int delay) {
this.text = text;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setFont(new Font("MS Gothic", Font.ITALIC, 24));
System.out.println(text);
g.drawString(text, 10, 50); // Draw the string up to the current index
System.out.println();
}
@Override
public void actionPerformed(ActionEvent e) {
repaint();
}
public static void main(String[] args) {
JFrame frame = new JFrame("Running String");
RunningStringPanel panel = new RunningStringPanel(getText(), 200);
frame.add(panel);
frame.setSize(400, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static final Long LONG_TIME = 1573430400000L;
public static String getText() {
Date created = new Date(LONG_TIME);
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
String value = format.format(created);
return value;
}
}
What we tried to solve the issue
Question: is there a way not to print rectangle in the string?
Upvotes: 0
Views: 29