LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-25-2004, 02:35 PM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
learn java help lz


Hi i am trying to learn Java but i have some problems... If you can help me ...

I want to know how i can show dynamicaly the fonts provided by my operating System in a choise (Fonts =new Choice()?

I want also need a choice for changing the colors of a string... I know how to create some colors in the choice...
Choice Fontcolor=new Choice();
Fontcolor.addItem("Red");
Fontcolor.addItem("Blue");

Do u know something better than this? For example something that i can use it immediately for changing the color.... I was thinkink if it is possible instead of text colors ..... to use colored lines in the choice... Is this possible?

Finally how i can change the color of a String?
I have a String inside a TextArea...i can;t find any option for this? Any suggestion?
Thx
 
Old 05-25-2004, 04:50 PM   #2
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
The first two for the moment Display availble fonts in a choice box below and swing has a custom class called JColorChooser to make easy selecting colours:
Code:


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;


public class FontView extends JFrame{
   
       
	private String fontNames[];
      
	private GraphicsEnvironment gEnv;
                private Choice fontChoices;
	
	private ItemListener listListener=new ItemListener(){
			public void itemStateChanged(ItemEvent ie){

                           if(ie.getStateChange()==ItemEvent.SELECTED)
                              System.out.println("You selected " + fontChoices.getSelectedItem());
	          
			}
                    };


   public FontView(){

         gEnv=GraphicsEnvironment.getLocalGraphicsEnvironment();
         fontNames=gEnv.getAvailableFontFamilyNames();
         	
         fontChoices=new Choice();
         fontChoices.addItemListener(listListener);
         setupFontChoices();
	        
         setSize(400,400);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

         getContentPane().add(fontChoices);       
	
         show();
       }


 private void setupFontChoices(){
      
	for(int i=0; i<fontNames.length;i++)
              fontChoices.add(fontNames[i]);
           
     }

public static void main(String args[]){

      FontView fv=new FontView();

 }
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Begin my first lesson to learn Java satimis Programming 9 02-18-2005 06:26 AM
The best way to learn? iz3r Programming 7 02-06-2005 11:00 PM
pls,advice me good website to learn Java vanhelsing Linux - Software 1 06-09-2004 01:24 PM
Do you really need to learn C before C++? qcoder Programming 31 12-04-2003 10:10 AM
Best way to learn.... InEeDhElPlInUx Linux - Newbie 5 10-11-2003 01:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration