JPHamlett 0 Share Posted December 29, 2020 I have the following code String dateToFormat(long time) { double hour = Math.floor(time); double minute = (time - hour) * 60; return String.format("%02d:%02d", hour, minute); } @Override public void onPaint(Graphics graphics) { int numPerHr = (int)(numMade / ((System.currentTimeMillis() - timeBegan) / 3600000.0D)); graphics.setColor(Color.BLUE); graphics.fillRect(518, 0, 246, 165); graphics.setColor(Color.BLACK); graphics.setFont(Font.getFont(Font.SERIF)); graphics.drawString("Running for: " + timer.formatTime(), 549, 25); graphics.drawString("Num made: " + numMade, 549, 50); graphics.drawString("Num per hour: " + numPerHr, 549, 75); graphics.drawString("Time remaining: " + dateToFormat(timer.remaining()), 549, 100); super.onPaint(graphics); } But when I run the script the paint looks like it's not rendering the final line Screengrab: https://imgur.com/9K9muTy So my questions are how do I get the last line to render, and why is my text so blurry? Link to comment Share on other sites More sharing options...
Pseudo 179 Share Posted December 29, 2020 Generally I've found in my personal scripts that the issue with strings not drawing is a logical error on my part, that's not to say it necessarily is in yours, but it may be worth double checking the method in question is operating as expected. (Try printing the result to the log). As for blurry text, I've found toggling Anti aliasing to be a big help, see below. Within onPaint: [code] Graphics2D g = (Graphics2D) graphics; g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); [/code] Link to comment Share on other sites More sharing options...
holic 233 Share Posted December 29, 2020 Wrap your paint with a try/catch and log the errors to find out what the problem is. try { ...paint... } catch (Exception e) { for (StackTraceElement ex : e.getStackTrace()) log("Error onPaint: " + ex.toString()); } Something like that should show you what's going on. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.