Chainging the color of a Keyword on Java

How do I highlight a keyword on Java ? I'm making a Java IDE which is for free
that you may see at : http://www.freewebs.com/cube-j I'm currently using a
3rd party jar file to make the keywords change its colors. The problem is
every 10 min a reminder will pop-out to remind me to register it for a fee.
I dont want to do that can anyone here show me how to do that or give some
sample on how to change the color of every keywords on JTextPane, Or does anyone
knows of a jar file which is free, thanks.
Hope to here from all of you . . .
Friend : BringMe2Life

I forget who I ripped the off (its someone here - camrickr I think), but this works very well import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
class SyntaxDocument extends DefaultStyledDocument{
                     private DefaultStyledDocument doc;
                     private Element rootElement;
     private boolean multiLineComment;
     private MutableAttributeSet normal;
     private MutableAttributeSet keyword;
     private MutableAttributeSet comment;
     private MutableAttributeSet quote;
     private Hashtable keywords;
        public SyntaxDocument(){
     doc = this;
     rootElement = doc.getDefaultRootElement();
     putProperty( DefaultEditorKit.EndOfLineStringProperty, "\n" );
     normal = new SimpleAttributeSet();
     StyleConstants.setForeground(normal, Color.black);
     comment = new SimpleAttributeSet();
                     Color green = new Color(0, 120, 0);
     StyleConstants.setForeground(comment, green);
     StyleConstants.setItalic(comment, true);
     keyword = new SimpleAttributeSet();
                     Color blue = new Color(0, 0, 140);
     StyleConstants.setForeground(keyword, blue);
     StyleConstants.setBold(keyword, true);
     quote = new SimpleAttributeSet();
                     Color red = new Color(140,0,0);
     StyleConstants.setForeground(quote, red);
     Object dummyObject = new Object();
     keywords = new Hashtable();
     keywords.put( "abstract", dummyObject );
     keywords.put( "boolean", dummyObject );
     keywords.put( "break", dummyObject );
     keywords.put( "byte", dummyObject );
     keywords.put( "byvalue", dummyObject );
     keywords.put( "case", dummyObject );
     keywords.put( "cast", dummyObject );
     keywords.put( "catch", dummyObject );
     keywords.put( "char", dummyObject );
     keywords.put( "class", dummyObject );
     keywords.put( "continue", dummyObject );
     keywords.put( "default", dummyObject );
     keywords.put( "do", dummyObject );
     keywords.put( "double", dummyObject );
     keywords.put( "else", dummyObject );
     keywords.put( "extends", dummyObject );
     keywords.put( "false", dummyObject );
     keywords.put( "final", dummyObject );
     keywords.put( "finally", dummyObject );
     keywords.put( "float", dummyObject );
     keywords.put( "for", dummyObject );
     keywords.put( "if", dummyObject );
     keywords.put( "implements", dummyObject );
     keywords.put( "import", dummyObject );
     keywords.put( "instanceof", dummyObject );
     keywords.put( "int", dummyObject );
     keywords.put( "interface", dummyObject );
     keywords.put( "long", dummyObject );
     keywords.put( "new", dummyObject );
     keywords.put( "null", dummyObject );
     keywords.put( "package", dummyObject );
     keywords.put( "private", dummyObject );
     keywords.put( "protected", dummyObject );
     keywords.put( "public", dummyObject );
     keywords.put( "return", dummyObject );
     keywords.put( "short", dummyObject );
     keywords.put( "static", dummyObject );
     keywords.put( "super", dummyObject );
     keywords.put( "switch", dummyObject );
     keywords.put( "synchronized", dummyObject );
     keywords.put( "this", dummyObject );
     keywords.put( "throw", dummyObject );
     keywords.put( "throws", dummyObject );
     keywords.put( "transient", dummyObject );
     keywords.put( "true", dummyObject );
     keywords.put( "try", dummyObject );
     keywords.put( "void", dummyObject );
     keywords.put( "volatile", dummyObject );
     keywords.put( "while", dummyObject );
* Override to apply syntax highlighting after the document has been updated
   public void insertString(int offset, String str, AttributeSet a) throws BadLocationException{
     if (str.equals("{"))
     str = addMatchingBrace(offset);
     super.insertString(offset, str, a);
     processChangedLines(offset, str.length());
* Override to apply syntax highlighting after the document has been updated
   public void remove(int offset, int length) throws BadLocationException{
     super.remove(offset, length);
     processChangedLines(offset, 0);
* Determine how many lines have been changed,
* then apply highlighting to each line
   private void processChangedLines(int offset, int length) throws BadLocationException {
     String content = doc.getText(0, doc.getLength());
     // The lines affected by the latest document update
     int startLine = rootElement.getElementIndex( offset );
     int endLine = rootElement.getElementIndex( offset + length );
     // Make sure all comment lines prior to the start line are commented
     // and determine if the start line is still in a multi line comment
     setMultiLineComment( commentLinesBefore( content, startLine ) );
     // Do the actual highlighting
           for (int i = startLine; i <= endLine; i++) applyHighlighting(content, i);
                     // Resolve highlighting to the next end multi line delimiter
           if (isMultiLineComment())commentLinesAfter(content, endLine);
                           else highlightLinesAfter(content, endLine);
* Highlight lines when a multi line comment is still 'open'
* (ie. matching end delimiter has not yet been encountered)
   private boolean commentLinesBefore(String content, int line){
     int offset = rootElement.getElement( line ).getStartOffset();
     // Start of comment not found, nothing to do
     int startDelimiter = lastIndexOf( content, getStartDelimiter(), offset-2);
     if (startDelimiter < 0)return false;
     // Matching start/end of comment found, nothing to do
     int endDelimiter = indexOf( content, getEndDelimiter(), startDelimiter );
     if (endDelimiter < offset & endDelimiter != -1)return false;
     // End of comment not found, highlight the lines
     doc.setCharacterAttributes(startDelimiter, offset - startDelimiter + 1, comment, false);
     return true;
* Highlight comment lines to matching end delimiter
   private void commentLinesAfter(String content, int line){
     int offset = rootElement.getElement( line ).getEndOffset();
     // End of comment not found, nothing to do
     int endDelimiter = indexOf( content, getEndDelimiter(), offset );
     if (endDelimiter < 0) return;
     // Matching start/end of comment found, comment the lines
     int startDelimiter = lastIndexOf( content, getStartDelimiter(), endDelimiter );
        if (startDelimiter < 0 || startDelimiter <= offset){
            doc.setCharacterAttributes(offset, endDelimiter - offset + 1, comment, false);
* Highlight lines to start or end delimiter
   private void highlightLinesAfter(String content, int line) throws BadLocationException{
     int offset = rootElement.getElement( line ).getEndOffset();
     // Start/End delimiter not found, nothing to do
     int startDelimiter = indexOf( content, getStartDelimiter(), offset );
     int endDelimiter = indexOf( content, getEndDelimiter(), offset );
     if (startDelimiter < 0)     startDelimiter = content.length();
     if (endDelimiter < 0)endDelimiter = content.length();
     int delimiter = Math.min(startDelimiter, endDelimiter);
     if (delimiter < offset)return;
     // Start/End delimiter found, reapply highlighting
     int endLine = rootElement.getElementIndex( delimiter );
        for (int i = line + 1; i < endLine; i++){
           Element branch = rootElement.getElement( i );
           Element leaf = doc.getCharacterElement( branch.getStartOffset() );
           AttributeSet as = leaf.getAttributes();
           if ( as.isEqual(comment) )applyHighlighting(content, i);
* Parse the line to determine the appropriate highlighting
   private void applyHighlighting(String content, int line) throws BadLocationException{
     int startOffset = rootElement.getElement( line ).getStartOffset();
     int endOffset = rootElement.getElement( line ).getEndOffset() - 1;
     int lineLength = endOffset - startOffset;
     int contentLength = content.length();
        if (endOffset >= contentLength)endOffset = contentLength - 1;
     // check for multi line comments
     // (always set the comment attribute for the entire line)
        if (endingMultiLineComment(content, startOffset, endOffset)
                             ||isMultiLineComment()||startingMultiLineComment(content, startOffset, endOffset)){
            doc.setCharacterAttributes(startOffset, endOffset - startOffset + 1, comment, false);
            return;
     // set normal attributes for the line
     doc.setCharacterAttributes(startOffset, lineLength, normal, true);
     // check for single line comment
     int index = content.indexOf(getSingleLineDelimiter(), startOffset);
         if ( (index > -1) && (index < endOffset) ){
             doc.setCharacterAttributes(index, endOffset - index + 1, comment, false);
             endOffset = index - 1;
     // check for tokens
     checkForTokens(content, startOffset, endOffset);
* Does this line contain the start delimiter
   private boolean startingMultiLineComment(String content, int startOffset, int endOffset) throws BadLocationException{
     int index = indexOf( content, getStartDelimiter(), startOffset );
     if ( (index < 0) || (index > endOffset) )return false;
     else{
         setMultiLineComment( true );
         return true;
* Does this line contain the end delimiter
   private boolean endingMultiLineComment(String content, int startOffset, int endOffset) throws BadLocationException{
     int index = indexOf( content, getEndDelimiter(), startOffset );
     if ( (index < 0) || (index > endOffset) )return false;
     else{
         setMultiLineComment( false );
         return true;
* We have found a start delimiter
* and are still searching for the end delimiter
   private boolean isMultiLineComment(){
       return multiLineComment;
   private void setMultiLineComment(boolean value){
       multiLineComment = value;
* Parse the line for tokens to highlight
   private void checkForTokens(String content, int startOffset, int endOffset){
       while (startOffset <= endOffset){
       // skip the delimiters to find the start of a new token
      while (isDelimiter(content.substring(startOffset, startOffset+1))){
          if (startOffset < endOffset)startOffset++;
          else return;
      // Extract and process the entire token
      if (isQuoteDelimiter( content.substring(startOffset, startOffset + 1)))
      startOffset = getQuoteToken(content, startOffset, endOffset);
      else startOffset = getOtherToken(content, startOffset, endOffset);
   private int getQuoteToken(String content, int startOffset, int endOffset){
     String quoteDelimiter = content.substring(startOffset, startOffset + 1);
     String escapeString = getEscapeString(quoteDelimiter);
     int index;
     int endOfQuote = startOffset;
     // skip over the escape quotes in this quote
     index = content.indexOf(escapeString, endOfQuote + 1);
     while ( (index > -1) && (index < endOffset) ){
        endOfQuote = index + 1;
        index = content.indexOf(escapeString, endOfQuote);
     // now find the matching delimiter
     index = content.indexOf(quoteDelimiter, endOfQuote + 1);
     if ( (index < 0) || (index > endOffset) )endOfQuote = endOffset;
     else endOfQuote = index;
     doc.setCharacterAttributes(startOffset, endOfQuote-startOffset+1, quote, false);
     return endOfQuote + 1;
    private int getOtherToken(String content, int startOffset, int endOffset){
     int endOfToken = startOffset + 1;
     while (endOfToken <= endOffset ){
     if (isDelimiter(content.substring(endOfToken, endOfToken+1)))break;
     endOfToken++;
    String token = content.substring(startOffset, endOfToken);
     if ( isKeyword( token ) )
     doc.setCharacterAttributes(startOffset, endOfToken-startOffset, keyword, false);
     return endOfToken + 1;
* Assume the needle will the found at the start/end of the line
    private int indexOf(String content, String needle, int offset){
     int index;
     while ( (index = content.indexOf(needle, offset)) != -1 ){
            String text = getLine( content, index ).trim();
         if (text.startsWith(needle) || text.endsWith(needle))break;
         else offset = index + 1;
     return index;
* Assume the needle will the found at the start/end of the line
    private int lastIndexOf(String content, String needle, int offset){
     int index;
     while ( (index = content.lastIndexOf(needle, offset)) != -1 ){
         String text = getLine( content, index ).trim();
         if (text.startsWith(needle) || text.endsWith(needle))break;
        else offset = index - 1;
     return index;
    private String getLine(String content, int offset){
     int line = rootElement.getElementIndex( offset );
     Element lineElement = rootElement.getElement( line );
     int start = lineElement.getStartOffset();
     int end = lineElement.getEndOffset();
     return content.substring(start, end - 1);
* Override for other languages
    protected boolean isDelimiter(String character){
     String operands = ";:{}()[]+-/%<=>!&|^~*";
     if (Character.isWhitespace( character.charAt(0) ) || operands.indexOf(character)!= -1 )
                          return true;
         else return false;
* Override for other languages
    protected boolean isQuoteDelimiter(String character){
                     String quoteDelimiters = "\"'";
     if (quoteDelimiters.indexOf(character) < 0) return false;
     else return true;
* Override for other languages
    protected boolean isKeyword(String token){
     Object o = keywords.get( token );
     return o == null ? false : true;
* Override for other languages
    protected String getStartDelimiter(){
     return "/*";
* Override for other languages
    protected String getEndDelimiter(){
     return "*/";
* Override for other languages
    protected String getSingleLineDelimiter(){
     return "//";
* Override for other languages
    protected String getEscapeString(String quoteDelimiter){
     return "\\" + quoteDelimiter;
    protected String addMatchingBrace(int offset) throws BadLocationException{
     StringBuffer whiteSpace = new StringBuffer();
     int line = rootElement.getElementIndex( offset );
     int i = rootElement.getElement(line).getStartOffset();
     while (true){
         String temp = doc.getText(i, 1);
         if (temp.equals(" ") || temp.equals("\t")){
             whiteSpace.append(temp);
             i++;
         else break;
     return "{\n" + whiteSpace.toString() + whiteSpace.toString()+"\n" + whiteSpace.toString() + "}";
}

Similar Messages

  • How to remove and change the color of Java cup and border

    Hi to all,
    How to remove and change the color of Java cup and border.
    Thanks in advance
    khiz_eng

    This is just an Image. You would need to create your own image and call setIconImage(Image) on your JFrame.

  • Can I change colors of the UI Elements related to WebDynPro Java

    Can I Change the colors of the UI Elements which are embedded in the view, for ex., Button, Label, Tray, etc... and Can I change other attributes like font style, size, etc...

    hi,
    just check out these links , may not be precise to your question but are useful
    Changing the colours of Table and Group Headers in Web Dynpro
    How to change color of label in web dynpro?
    /people/sap.user72/blog/2006/04/25/colourful-table-in-web-dynpro
    Regarding Design of background color in a Web Dynpro Table
    Colors in WD - Java
    displaying color for a particular column item in a table
    hope it helps
    regards

  • I am trying to connect a Macbook Pro to a projector for a Powerpoint presentation. When I use a VGA cable, the color of the projected images are not good. When I use a USB cable, the projected image includes the presenter notes on my computer screen?

    I am trying to connect a Macbook Pro to a projector for a Powerpoint presentation. When I use a VGA cable, the color of the projected images are not good. When I use a USB cable, the projected image includes the presenter notes on my computer screen?

    To move an iPhoto Library to a new machine:
    Link the two Macs together: there are several ways to do this: Wireless Network,Firewire Target Disk Mode, Ethernet, or even just copy the Library to an external HD and then on to the new machine...
    But however you do choose to link the two machines...
    Simply copy the iPhoto Library from the Pictures Folder on the old Machine to the Pictures Folder on the new Machine.
    Then hold down the option (or alt) key key and launch iPhoto. From the resulting menu select 'Choose Library'
    and select the Library that you moved.  That's it.
    This moves photos, events, albums, books, keywords, slideshows and everything else.
    Your first option didn't work because you imported one Library to another. Every version and thumbnail is imported like a distinct photo, you lose all your Albums, Keywords etc., the link between Original and Previews is destroyed, the non-destructive editing feature is ruined and so on. In summary: it's mess.
    Your second option didn't work because you simply referenced her library on the old machine.
    Regards
    TD

  • How to change the Color of a string using swings/awt concept.

    Hi friends,
    How can i change the Color of a string.
    For ex:
    If i have a string "Welcome to the Java World",I want one particular Color for the string "Welcome to the" and a different Color to the "Java World" string.
    So please kindly help me out to resolve this issue.
    Thanking u in advance.

    "Text Component Features"
    http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html

  • Can I change the color of the text in a slideshow?

    It loooks ok on the page but when you click on the photo the text is a different color.

    That's the way it was designed by Apple.  The photo descriptions in that mode is generated by the code.  If you know java code you probably could edit the js file in the site that controls the description's font and color.  It's beyond me. You could change the theme to the Black theme and the photo descriptions would be white on the thumbnail page and on the mosaic mode page.  If you have a different background you can modify the black theme to match what you're using for backgrounds ,etc.

  • How can i change the color in textarea

    Hi to all, i am making the chat application in java , i want to show the client message in different color in text area , i have only one window which shows both client and server messages . i am sending you my program can u tell me how to change the color.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    public class cwDraft extends JFrame {
    static private JTextField enter;//user write text in this area
    private JTextField ip;
    static private JTextArea display;
         JButton b1;
         JButton connect;
    static String s=" ";
    static String s1=" ";
    static String s2=" ";
         static DatagramSocket socket;
         static DatagramPacket packet;
         cwDraft() {
              super("chat server");
              setSize(400, 300);
              Container c = getContentPane();
              //c.setLayout(new FlowLayout());-
              display=new JTextArea();
              display.setToolTipText("display area");
              c.add(new JScrollPane(display),BorderLayout.CENTER);
              ip=new JTextField("127.0.0.1",15);
              ip.setToolTipText("enter ip here");
              c.add(ip,BorderLayout.EAST);
              enter=new JTextField(30);
              enter.setToolTipText("enter message");
         c.add(enter,BorderLayout.NORTH);
              b1 = new JButton("Send");
              b1.setToolTipText("send message");
              b1.addActionListener(new B1Listener());
              connect=new JButton("connect");
              connect.setToolTipText("connect to other computer");
              c.add(connect,BorderLayout.SOUTH);
              connect.addActionListener(new ConnectListener() );
              //enter=new JTextField();
              c.add(b1,BorderLayout.WEST);
              show();
              addWindowListener(
              new WindowAdapter() {
              public void windowClosing(WindowEvent e) {
              System.exit(0);
         } // constructor
         public static void main(String[] args) {
              new cwDraft();
              try {
                   socket = new DatagramSocket(3082);
              } catch(Exception ex) {
                   ex.printStackTrace();
              do {
                   byte data[] = new byte[100];
                   packet = new DatagramPacket(data, data.length);
                   try {
                        socket.receive(packet);                    
                   //display.append(s2);
                   } catch(Exception ex) {
                        ex.printStackTrace();
                   s1 = new String(packet.getData(), 0, packet.getLength());
                   //System.out.println(s);
                   display.append(packet.getAddress() +"says"+ s1 +"\n");
              } while(true);     
         } // main
         private class B1Listener implements ActionListener {
              public void actionPerformed(ActionEvent e) {
                   s = enter.getText();          
                   byte data[] = s.getBytes();
                   try {
                   //     packet1 = new DatagramPacket(data, data.length);
                        packet = new DatagramPacket(data, data.length, InetAddress.getByName(ip.getText()), 3082);
                        socket.send(packet);
                        display.append(packet.getAddress() +"says"+ s +"\n");
                   } catch(Exception ex) {
                        ex.printStackTrace();
                   //enter.setText(s2);
              } // actionPerformed
         } // B1Listener
    private class ConnectListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
         //String s1=" ";
         byte data[]=s.getBytes();
         try {
                        packet = new DatagramPacket(data, data.length, InetAddress.getByName(ip.getText()), 3082);
                        display.append("connected to:" + packet.getAddress() +"\n");
    catch(Exception ex) {
                        ex.printStackTrace();
    } // class

    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.Color;
    public class MultiColouredText extends JFrame {
       public MultiColouredText() {
       StyledDocument doc = new DefaultStyledDocument();
       JTextPane pane = new JTextPane(doc);
       pane.setEditable(false);
       pane.setFont(new java.awt.Font("Verdana", 0 , 16));
       MutableAttributeSet mas = new SimpleAttributeSet();
          try {
             StyleConstants.setForeground(mas, Color.yellow);
             StyleConstants.setBackground(mas, Color.blue);
             doc.insertString(doc.getLength(), " Hello ", mas);
             StyleConstants.setForeground(mas, Color.blue);
             StyleConstants.setBackground(mas, Color.yellow);
             doc.insertString(doc.getLength(), " World ", mas);
             StyleConstants.setForeground(mas, Color.red);
             StyleConstants.setBackground(mas, Color.green);
             doc.insertString(doc.getLength(), " And ", mas);
             StyleConstants.setForeground(mas, Color.green);
             StyleConstants.setBackground(mas, Color.red);
             doc.insertString(doc.getLength(), " Farewell ", mas);
          catch (Exception ignore) {}
       getContentPane().add(pane);
       setSize(250,56);
       show();
       public static void main(String[] args) {
          new MultiColouredText();
    }

  • I get the message Exception in thread "main" java.lang.StackOverflowError

    I'm trying to make a program for my class and when I run the program I get the error Exception in thread "main" java.lang.StackOverflowError, I have looked up what it means and I don't see where in my program would be giving the error, can someone please help me, here is the program
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    // This visual application allows users to "shop" for items,
    // maintaining a "shopping cart" of items purchased so far.
    public class ShoppingApp extends JFrame
    implements ActionListener {
    private JButton addButton, // Add item to cart
    removeButton; // Remove item from cart
    private JTextArea itemsArea, // Where list of items for sale displayed
    cartArea; // Where shopping cart displayed
    private JTextField itemField, // Where name of item entered
    messageField; // Status messages displayed
    private ShoppingCart cart; // Reference to support object representing
    // Shopping cart (that is, the business logic)
    String itemEntered;
    public ShoppingApp() {
    // This array of items is used to set up the cart
    String[] items = new String[5];
    items[0] = "Computer";
    items[1] = "Monitor";
    items[2] = "Printer";
    items[3] = "Scanner";
    items[4] = "Camera";
    // Construct the shopping cart support object
    cart = new ShoppingCart(items);
    // Contruct visual components
    addButton = new JButton("ADD");
    removeButton = new JButton("REMOVE");
    itemsArea = new JTextArea(6, 8);
    cartArea = new JTextArea(6, 20);
    itemField = new JTextField(12);
    messageField = new JTextField(20);
    // Listen for events on buttons
    addButton.addActionListener(this);
    removeButton.addActionListener(this);
    // The list of items is not editable, and is in light grey (to
    // make it distinct from the cart area -- this would be done
    // better by using the BorderFactory class).
    itemsArea.setEditable(false);
    itemsArea.setBackground(Color.lightGray);
    cartArea.setEditable(false);
    // Write the list of items into the itemsArea
    itemsArea.setText("Items for sale:");
    for (int i = 0; i < items.length; i++)
    itemsArea.append("\n" + items);
    // Write the initial state of the cart into the cartArea
    cartArea.setText("No items in cart");
    // Construct layouts and add components
    JPanel mainPanel = new JPanel(new BorderLayout());
    getContentPane().add(mainPanel);
    JPanel controlPanel = new JPanel(new GridLayout(1, 4));
    controlPanel.add(new JLabel("Item: ", JLabel.RIGHT));
    controlPanel.add(itemField);
    controlPanel.add(addButton);
    controlPanel.add(removeButton);
    mainPanel.add(controlPanel, "North");
    mainPanel.add(itemsArea, "West");
    mainPanel.add(cartArea, "Center");
    mainPanel.add(messageField, "South");
    public void actionPerformed(ActionEvent e)
    itemEntered=itemField.getText();
    if (addButton==e.getSource())
    cart.addComputer();
         messageField.setText("Computer added to the shopping cart");
    public static void main(String[] args) {
    ShoppingApp s = new ShoppingApp();
    s.setSize(360, 180);
    s.show();
    this is a seperate file called ShoppingCart
    public class ShoppingCart extends ShoppingApp
    private String[] items;
    private int[] quantity;
    public ShoppingCart (String[] inputitems)
    super();
    items=inputitems;
    quantity=new int[items.length];
    public void addComputer()
    int x;
    for (x=0; "computer".equals(itemEntered); x++)
         items[x]="computer";
    please somebody help me, this thing is due tomorrow I need help asap!

    First, whenever you post, there is a link for Formatting Help. This link takes you to here: http://forum.java.sun.com/features.jsp#Formatting and tells you how to use the code and /code tags so any code you post will be easily readable.
    Your problem is this: ShoppingApp has a ShoppingCart and ShoppingCart is a ShoppingApp - that is ShoppingCart extends ShoppintApp. You are saying that ShoppingCart is a ShoppingApp - which probably doesn't make sense. But the problem is a child class always calls one of its parent's constructors. So when you create a ShoppingApp, the ShoppingApp constructor tries to create a ShoppingCart. The ShoppingCart calls its superclass constructor, which tries to create a ShoppingCart, which calls its superclass constructor, which tries to create a ShoppingCart, which...
    It seems like ShoppingCart should not extend ShoppingApp.

  • How do i change the color of a JTable's column names

    hai,
    i'm very new to java and trying to customize the look of a JTable.
    how do i change the color of a JTable's Column names. i know its very simple, i just couldn't figure out how to do it!!
    thanx in advance

    table.getTableHeader().setForeground(Color.RED);

  • How to change the color of a title bar

    Hello !
    I try to change the color from my title bars, but I fail.
    I tried to change the activeCaption value to an other colour, but that didn�t work. Currently I use a own LAF and set it with UIManager.setLookAndFeel("dpg.beans.GuiWindowsLookAndFeel");
    import javax.swing.UIDefaults;
    import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
    public class GuiWindowsLookAndFeel extends WindowsLookAndFeel {
      protected void initSystemColorDefaults(UIDefaults table) {
        String[] colors = {
           "activeCaption", "#B0171F" 
         loadSystemColors(table, colors, false);
    }I also used the complete stringarray from WindowsLookAndFeel and only changed that one color. Still no changes.
    Any ideas ?

    import javax.swing.*;
    import java.awt.*;
    class Testing
      public void buildGUI()
        UIManager.put("activeCaption", new javax.swing.plaf.ColorUIResource(Color.YELLOW));
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame f = new JFrame();
        f.setSize(200,100);
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }

  • How to Change the color of the black image

    Hi,
    I have created a black image. But want to insert some text and chnage the color of the same. I am trying to do it, by usign various classes of javax.imageio.*, java.awt.image. But, I have not the required output till now. I am showing my code below. The image I created is totally black.
    Any suggestion greatly appreciated.
    File f = new File("C:/tomcat5.5.15/apache-tomcat-5.5.16/webapps/plugintest/03974701.jpg");
    BufferedImage image = ImageIO.read(f);
    int height = image.getHeight();
    int width = image.getWidth();
    int type = image.getType();
    ColorModel cm = image.getColorModel();
    System.out.println("Width of the Image is "+width);
    System.out.println("Height of the Image is "+height);
    System.out.println("type of the Image is "+type);
    BufferedImage image1 = new BufferedImage(width,height,type);
    //image1.setRGB(45,45,rgb);
    File f1 = new File("blank.jpg");
    RenderedImage ri = image1;
    ImageIO.write(ri,"jpg",f1);

    Color c = new Color(0, 0, 0);
    Graphics g = image1.getGraphics();
    g.setColor(c);Thanks for your suggestion I added these lines to the
    code(code is shown above), but the there is no change
    in the color of the jpg image saved in the file. Am I
    missing something.Yes.
    a) Do you know what color 0,0,0 is? Hint: not mauve
    b) When you call set color that sets the drawing colour. But you aren't drawing anything. You can draw things with the methods of Graphics and Graphics2D. I suggest starting with fillRect
    http://java.sun.com/developer/Books/Graphics/
    Thanks

  • Change the color of the text in textpane

    please suggest me how to change the color of the selected text color in textpane in jpanel
    class ComposeMailPanel extends JPanel implements ListSelectionListener, ActionListener, ItemListener
    JFrame frame;
    JTextPane jtextpane;
    JButton bInsertPic;
    JButton bBackgroundColor;
    JButton bForegroundColor;
    JFileChooser selectedFile;
    JFileChooser insertIconFile;
    JColorChooser backgroundChooser;
    JColorChooser foregroundChooser;
    JComboBox fontSize;
    SimpleAttributeSet sas;
    MutableAttributeSet sas1;
    StyleContext sc;
    DefaultStyledDocument dse;
    JScrollPane mainScrollPane;
    RTFEditorKit rtfkit;
    JComboBox fontFamily;
    MutableAttributeSet mas;
    Color backgroundColor;
    Color foregroundColor;
    String SF = "";
    public ComposeMailPanel()
         setLayout(null);
    bInsertPic = new JButton("Insert picture");
    add(bInsertPic);
    bInsertPic.setBounds(150,460,110,20);
    bInsertPic.setBackground(new Color(0,139,142));
    bInsertPic.setForeground(new Color(255,255,255) );
    bInsertPic.setBorder(borcolor);
    bInsertPic.addActionListener(this);
    bForegroundColor = new JButton("Set foreground color");
    add(bForegroundColor);
    bForegroundColor.setBounds(270,460,130,20);
    bForegroundColor.setBackground(new Color(0,139,142));
    bForegroundColor.setForeground(new Color(255,255,255) );
    bForegroundColor.setBorder(borcolor);
    bForegroundColor.addActionListener(this);
    fontFamily=new JComboBox();
    combofontfamilyinitialize();
    add(fontFamily);
    fontFamily.setBounds(420,460,110,20);
    fontFamily.setBackground(new Color(0,139,142));
    fontFamily.setForeground(new Color(255,255,255) );
    fontFamily.setBorder(borcolor);
    fontFamily.addItemListener(this);
    fontSize = new JComboBox();
    add(fontSize);
    fontSize.setBounds(550,460,40,20);
    fontSize.setBackground(new Color(0,139,142));
    fontSize.setForeground(new Color(255,255,255) );
    fontSize.setBorder(borcolor);
    fontSize.addItemListener(this);
    combofontsizeinitialize();
    sas = new SimpleAttributeSet();
    sas1 = new SimpleAttributeSet();
    sc = new StyleContext();
    dse = new DefaultStyledDocument(sc);
    rtfkit = new RTFEditorKit();
    selectedFile = new JFileChooser();
    insertIconFile = new JFileChooser();
    backgroundChooser = new JColorChooser();
    foregroundChooser = new JColorChooser();
         JScrollPane scrollPane2 = new JScrollPane();
         add(scrollPane2);
         scrollPane2.setBounds(150,300,577,152);
         jtextpane= new JTextPane();
         scrollPane2.getViewport().add(jtextpane);
         jtextpane.setBounds(150,300,572,150);
         jtextpane.setDocument(dse);
         jtextpane.setContentType( "text/html" );
         jtextpane.setEditable( true );
         jtextpane.setBackground(new Color(255,255,255));
         //jtextpane.setFont(new Font( "Serif", Font.PLAIN, 12 ));
         jtextpane.setForeground(new Color(0,0,0) );
         setBackground(new Color(0,139,142));
              }//constructor
    public void combofontfamilyinitialize ()
    GraphicsEnvironment ge1 = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] k = ge1.getAvailableFontFamilyNames();
    fontFamily= new JComboBox(k);
    public void combofontsizeinitialize ()
    //This function fills the combo box with font sizes
    fontSize.addItem("8");
    fontSize.addItem("9");
    fontSize.addItem("10");
    fontSize.addItem("11");
    fontSize.addItem("12");
    fontSize.addItem("14");
    public void setAttributeSet(AttributeSet attr)
    //This function only set the specified font set by the
    //attr variable to the text selected by the mouse
    int xStart, xFinish, k;
    xStart = jtextpane.getSelectionStart();
    xFinish = jtextpane.getSelectionEnd();
    k = xFinish - xStart;
    if(xStart != xFinish)
    dse.setCharacterAttributes(xStart, k, attr, false);
    else if(xStart == xFinish)
    //The below two command line updates the JTextPane according to what
    //font that is being selected at a particular moment
    mas = rtfkit.getInputAttributes();
    mas.addAttributes(attr);
    //The below command line sets the focus to the JTextPane
    jtextpane.grabFocus();
    public void actionPerformed(ActionEvent ae1)
    JComponent b = (JComponent)ae1.getSource();
    String str3 = null;
    frame = new JFrame();
    if(b == bInsertPic)
    System.out.println("inside insertpic");
    insertIconFile.setDialogType(JFileChooser.OPEN_DIALOG);
    insertIconFile.setDialogTitle("Select a picture to insert into document");
    if(insertIconFile.showDialog(frame,"Insert") != JFileChooser.APPROVE_OPTION)
    System.out.println("inside icon");
    return;
    File g = insertIconFile.getSelectedFile();
    ImageIcon image1 = new ImageIcon(g.toString());
    jtextpane.insertIcon(image1);
    jtextpane.grabFocus();
    else if(b == bForegroundColor)
              foregroundColor = foregroundChooser.showDialog(frame, "Color Chooser", Color.white);
    if(foregroundColor != null)
    String s1=jtextpane.getSelectedText();
         StyleConstants.setForeground(sas, foregroundColor);
    setAttributeSet(sas);
    public void itemStateChanged(ItemEvent ee5) {
    JComponent c = (JComponent)event.getSource();
    boolean d;
    if(c == fontFamily)
    String j = (String)fontFamily.getSelectedItem();
    StyleConstants.setFontFamily(sas, j);
    setAttributeSet(sas);
    else if(c == fontSize)
    String h = (String)fontSize.getSelectedItem();
    int r = Integer.parseInt(h);
    StyleConstants.setFontSize(sas, r);
    setAttributeSet(sas);
    thanks in advance

    Learn how to use the forum correctly by posting formatted code.
    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html]Text Component Features.

  • How can we change the  color of the image for product display for different

    Hi All,
    How can we change the  color of the image for product display for different colors, to be displayed on site.
    jeff

    Hi priya,
    The requirement that you have stated is not a standard feature in ISA CRM. In order to do the same, you will need to modify the standard ISA code in Java. A common path for the solution would be as follows:
    1. Colours
        a. Maintain a text type for Color under the object - PCAT_ITM in Customizing.
        b. Modify the standard search of ISA to search within your new text type as well. (In standard it only searches in Description.
       c. Maintain all shirts colour data in the new type created in step a.
       d. Your requirement will be done!
    2. Price
      a. Use list prices for your shop and assign the appropriate condition type, acces in your catalog.
      b. Modify the standard search of ISA to search on the list prices as well.
      c. This too will be done!
    3. Accessories - This is very tricky, and will require some exploration. However, here's my opinion,
    a. Search for the standard function module, which will return the accessories when provided the product as an input.
    b. Modify this function module according to your requirement and ensure that it can be accessed remotely.
    c. Modify the JSP as in steps 1b and 2b above to call this new remote-enabled function module.
    d. Now you're done!!
    The ISA modification part is not so simple, you need a really good guy like "Sateesh Chandra" who'll be able to handle your requirements. This is all I could manage, hope it is some help to you!
    Thanks & Regards,
    Nelson.

  • How to read the color of pixels on the desktop?

    Hi All!
    how is it possible to read the color of certain pixels on the screen? This is not withing any GUI or graphical java application. That is, the java program is supposed to be invisible to the user, run in the background and have access to the color information on the desktop. I have no idea if this possible at all and don't know how to search for it. With which functions/APIs is it possible?
    Would be very thankful for any hints!!
    Alex.

    Thanks a lot! this is exactly what I was looking for. Moreover, this class has other good things like how to control mouse, which I was also looking for.
    So, you answered two my questions : )
    Many thanks agian!!

  • How do i do change the color(complete newbie)

    i want to have a special button inside the applet which will automatically change the color from red to yellow,
    HELP!!!
    import java.awt.*;
    import java.applet.Applet;
    import java.awt.event.*;
    public class Cookie extends Applet
        implements AdjustmentListener {
        private Scrollbar slider;
        private int sliderValue;
        public void init () {
            slider = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,51);
            add(slider);
            slider.addAdjustmentListener(this);
        public void paint (Graphics g) {
            showStatus("Scrollbar value is " + sliderValue);
              g.setColor(Color.black);
              g.drawRect(60, 60, 60, 100);
              g.setColor(Color.red);
              g.fillRect(60, 160-sliderValue, 60, sliderValue);
            g.fillRect(60, 60, 60, sliderValue);
        public void adjustmentValueChanged(AdjustmentEvent e) {
            sliderValue = slider.getValue();
            repaint();
    }

    This seems awfully familiar!
    Add a boolean to keep track of color.
    Your "special button" will have fire off an actionEvent, in actionPerformed set your boolean to true or false.
    In the paint method check for true or false of the boolean and setColor accordingly.

Maybe you are looking for

  • Hyperlinks not saved correctly in PDF and Excel

    Hi, I have a few reports with hyperlinks to other reports that contain multiple input parameters, which makes the links very long. ( greater than 400 characters ) When the reports are saved as excel, I am unable to invoke the child report on clicking

  • Select-option in ABAP objects

    Hi Guys,            I need a small help from you. I want to know how to populate the value from select-option to abap object. Please help me, it is very important

  • Problem in Saving long texts from IC Webclient

    Hi, I have a little problem with BP long text transfert. In IC Webclient, I identify a account and I create a long text (for exemple a Accounting Note). I can find this text in CRM (t-code BP->long text) but, it is not transfert to ECC (XD03->Extra->

  • Oracle 11.2.0.4  DeriveParameters not working with XMLType

    Hi folks, this has me stumped and can't find anyone talking about it. We're using ODP (non-managed).  Calling OracleCommandBuilder.DeriveParameters to get a parameter collection for SP that inserts a record into a table. The table contains a Column o

  • BeforeReportTrigger , Data Template and Parameters

    Hi I'm new to XML publisher. Things has been going quite smoothly until I started to introduce BeforeReportTriggers and Parameters in my Data Template. When I go to view the report, I get "The report cannot be rendered because of an error, please con