Change the font size in G4P library Label?

edited October 2013 in Library Questions

@quark I'd like to change the font size of a G4P label, but can't figure it out from the ref doc. How do I do this? I'd also like to figure out how to make a custom color scheme too.



  • edited October 2013 Answer ✓

    Two things here

    1) Change the font size for a GLabel

    label.setFont(new Font("Monospaced", Font.PLAIN, 12));

    The first parameter is the font family and I suggest you restrict this to Dialog, DialogInput, Monospaced, Serif or SanSerif as the JVM has cross-platform support for these logical fonts (according to Oracle) but some fonts like Ariel and Times New Roman are probably OK to use. I would leave it as Font.PLAIN since you can use the setItalic, setBold and setPlain methods (see GTextBase class API) to set these attributes for all or part of the label text. Obviously 12 is the font size.

    2) Creating a custom colour scheme

    In the Processing | libraries | G4P | src | data folder you will find a file called 'default_gui_palette.png' it looks like this.

    scheme image.

    Copy this image to the data folder inside your sketch folder and rename it 'user_gui_palette.png'. The next time you run the sketch it will use this image instead of the default one.

    As you can see the first eight schemes (0-7) are the pre-existing schemes but you can use the other eight (8-15) for yourself. I suggest that you copy the showcase example sketch add your user defined scheme image. Then simply change the event code for one of the colour selection buttons to use number 8. You can then see how your scheme will work with the different controls.

  • Excellent, thank you! G4P and the GUI Builder are really accelerating my code development. Thanks again.

  • @quark:

    Custom colors worked well, but when I attempted to modify the label font size I got an error:

    The method setFont(Font) in the type GTextBase is not applicable for the arguments (Font)

    I have a label with the variable name mouseX_location, so I am typing into the customGUI() block:

    mouseX_location.setFont(new Font("Monospaced", Font.PLAIN, 20));

    What did I miss?

  • Interesting - for a minute I thought that I had made a mistake and that the setFont method was an addition for the next version of G4P (due out soon) but the error message shows that it found the method but didn't recognise the parameter as a suitable Font.

    *-:) The most likely cause is that you have an import for a different Font class than the one used by G4P. Make sure you have one of the following import statements

    import java.awt.Font; import java.awt.*;

    and delete any other font import statement.

  • Okay, tried that, but now I get the error:

    The field Component.fort is not visible.

  • The field Component.fort is not visible.

    I think you mean Component.font?

    First of all I do not believe this problem is caused by G4P, I have used setFont in several projects and I suspect there is a conflict with some other library you are using. So please answer the following questions

    What other libraries (if any) are you importing?

    Are you using and Java controls as well as G4P?

    Please post the imports section of your sketch.

    Having said all that I suggest you put back any Font imports that you might have removed after my last post, make sure you have the following import

    import java.awt.Font;

    and then set the labels font with

    mouseX_location.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 20));

    and let me know if it worked. [-O<

  • Okay, that did the trick. Changed Font... to java.awt.Font... Thank you so much for the help!

  • edited March 2014

    what type of font should be used to obtain equal charts when moving text hexa.GUI builder

    // Need G4P library
    import g4p_controls.*;
    import javax.swing.*;
    int size = 2048;
    byte [] dataOutput = new  byte [size] ;
    public String [] linia = new String [size/16];
    public void setup(){
      size(480, 320, JAVA2D);
      // Place your setup code here
      PFont myFont;
    // myFont = loadFont("Calibri-24.vlw");
      myFont = loadFont("Monospaced.bold-24.vlw");
      for (int i = 0; i < size; i++  ) {
        dataOutput[i] = (byte) random (256);
  • You cannot change the font used by G4P controls using Processing's textFont, this is used ONLY when using Processing's 'text(...)' function.

    To set the font for the GTextArea control called textarea1 to 24pt monospaced use

    textarea1.setFont(new Font("Monospaced", Font.PLAIN, 24));

    you will also need to use the import

    'import java.awt.Font;'

  • thanks, this is working.

  • Hello, I hope that I have found the right thread, please forgive me if I didn't. I want to change to a custom color scheme and already edited the image and saved it, but how to use it in my sketch? I already found the g4p_controls.GCScheme.changePalette() but I don't know which parameters it is expecting. Thanks in advance!

  • @LukasAV

    This discussion is about changing the font size in G4P, your question is on a different topic so it would have been better to create a new discussion in the "Library Questions" category.

    This topic has been marked as answered so it was only luck that I found your question.

    Don't worry about it, just rember for the future.

    If you have edited and saved the image and in png format then smply rename the file

    and put it inside the sketch folder and that's it :)

  • Thank you for your answer, I will create a new discussion the next time. I selected the blue color scheme in the GUI Builder and replaced the blue line with my own colors in the user_gui_palette.png so it worked. My problem was that I had used the free spaces below the colors that already existed which I could not select as a color scheme.

Sign In or Register to comment.