Raunoo321 Posted November 4, 2020 Share Posted November 4, 2020 Hey! Maybe for some its stupid question, but personally I after using java for so long, I've never had to use nor graphics so deep or used color codes that much. So my question: Situation is g.setColor(Color.BLUE); g.drawString("blabla" + someStringVariable), 20, 50); So how can I keep that blabla or whatever as blue and change variable color to I don't know, to yellow? Like how can I make it happen, or is there any chance that I can change colors in drawString with colorcodes? Dunno, my english isn't perfect, but I'm giving my best Quote Link to comment Share on other sites More sharing options...
Hawk Posted November 4, 2020 Share Posted November 4, 2020 If I understand your problem correctly you want to do something like blabla someStringVariable in one drawString call? I don't think it's possible to do it in one drawString call, but this works, taken from https://stackoverflow.com/questions/23591034/how-to-use-multiple-colors-when-using-drawstring-in-java-awt-graphics public class Test extends Script { private static final String s = "<html>all your <font color=\"#ffd700\">base</font> belong to us</html>"; private JLabel renderer = new JLabel(s); private CellRendererPane crp = new CellRendererPane(); private Dimension dim = renderer.getPreferredSize(); @Override public int onLoop() throws InterruptedException { return 10000; } @Override public void onPaint(Graphics2D g) { renderer.setForeground(Color.BLUE); crp.paintComponent(g, renderer, bot.getBotPanel(), 10, 10, dim.width, dim.height); } } 2 Quote Link to comment Share on other sites More sharing options...
Raunoo321 Posted November 4, 2020 Author Share Posted November 4, 2020 Thanks Quote Link to comment Share on other sites More sharing options...