Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java Fonts And Text Layout Layout

  • 01-05-2008 4:55pm
    #1
    Registered Users, Registered Users 2 Posts: 538 ✭✭✭


    Hello,
    I have been getting some errors when trying to make my font bold, below are the attempts i have made but to no avail.

    [PHP]

    Font myFont= new Font ("Comic Sans MS",0,14,"Font.Bold");

    Font myFont= new Font ("Comic Sans MS",0,14,"Bold");

    Font myFont= new Font ("Comic Sans MS",0,14,".Font.Bold");

    Font myFont= new Font ("Comic Sans MS",0,14,Font.Bold);

    Font myFont= new Font ("Comic Sans MS",0,14,Bold);

    [/PHP]
    I also want to be able to manage the layout of the text so i can move it to the right layout
    [PHP]
    JLabel myLabel0 = new JLabel("Customer ID:");
    JTextField myTextField0 = new JTextField(20);
    JLabel myLabel1 = new JLabel("First Name:");
    JTextField myTextField1 = new JTextField(20);
    JLabel myLabel2 = new JLabel("Surname:");
    JTextField myTextField2 = new JTextField(20);
    JLabel myLabel3 = new JLabel("Street:");
    JTextField myTextField3 = new JTextField(20);


    myJPanel1.setBackground(myColor);
    myJPanel1.setFont(myFont);
    myJPanel1.add(myLabel0);
    myJPanel1.add(myTextField0);
    myJPanel1.add(myLabel1);
    myJPanel1.add(myTextField1);
    myJPanel1.add(myLabel2);
    myJPanel1.add(myTextField2);
    myJPanel1.add(myLabel3);
    [/PHP]
    etc

    Is anyone able to help


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    What are the errors?


  • Registered Users, Registered Users 2 Posts: 196 ✭✭juror


    This will work,
    Font myFont = new Font("Comic Sans MS", 14, Font.BOLD);
    

    You have too many parameters in your constructor, I'm not sure what the 0 value you have put in is for?

    But the above line of code will work. If your're looking for java assisstance in contructors and the like check out the online API,

    http://java.sun.com/javase/6/docs/api/


  • Moderators, Science, Health & Environment Moderators Posts: 10,088 Mod ✭✭✭✭marco_polo


    I think that that to get the components contained within the Jpanel (buttons, labels etc) to use the parent font (the one set in the JPanel) you will have to call setFont(null) on each component individually.

    This is because when you create a JLabel, JButton etc it already has a default font type. By setting it to null you are telling it to go look for the Font of its parent component.
    myLabel0.setFont(null);
    ...etc....
    

    The alternative is to call setFont(myFont) on each of the components individually, which is really the exact same thing.

    Ass I am sure you have figured out by now, Swing programming is a pain in the ass :).


  • Registered Users, Registered Users 2 Posts: 538 ✭✭✭ComplyOrDie


    Thanks for your responces. That last suggestion gave me some complier errors. However when he questioner the 0 it got me thinking and after some messing around i found following

    0 = Plain
    1 = Bold
    2 = Italic
    3 = Bold + Italic

    hope this helps you's in the future

    [PHP]


    Font myFont= new Font ("Comic Sans MS",1,14);

    Font myFont= new Font ("Comic Sans MS",2,14);

    Font myFont= new Font ("Comic Sans MS",3,14);
    [/PHP]

    Thanks Again

    ComplyOrDie


Advertisement