Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I have a doubt  RSS feed

 
Priya Pichamuthu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I put a text area under a text field in a swing GUI. Will the code be different from the one where I put a text area to the side of a text field? How do we determine the position of the text field and text area relative to each other?
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This depends completely on the LayoutManager you are using (e.g. BoxLayout, BorderLayout, etc.).
Check out Sun's tutorials on Using Swing Layout Managers on their website.
Bill
 
Priya Pichamuthu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. But how do I write sentences in different colors on a GUI? Like I have a sentence
static string s = "Sparky the Dog";
How do I make it appear on the GUI in red color?
 
Vikalp Setya
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You have to create labels out of the text and set their foreground color to the desired color and then add them to the content pane.
import java.awt.*;
import javax.swing.*;
static String someText = "Java";
JLabel label = new JLabel(someText);
label.setForeground(Color.red);
getContentPane().add(label);
It depends upon the layout manager where you add the created label.I have put it in the content pane.
Regards,
vikalp_setya@rediffmail.com
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!