Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: I give up. Need help changing color of JTabbedPane selected Tab. I've Googled so hard

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I give up. Need help changing color of JTabbedPane selected Tab. I've Googled so hard

    I've been googling this for several hours. None of the solutions I've found have worked for me. I'm trying to make the JTabbedPane's selected tab's color change.
    Sorry the code is long, but it's all at the top, and I think it's something with the rest of the code that's affecting it, as all the examples I've tried have worked.

    P.S. Please help. I'm really at my wit's end.

    Edit: Clearly I'm new. I hope I posted correctly.

    /* Applet skeleton
     * @author :
     * Date : 
     */
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    public class AppletName extends JApplet
     {
    	//Movie Tab Declarations
    	JPanel applet;
     
    	// Movie Tab Declarations
    	JLabel title, moviesimagelabel, movietitle, moviedateacquired, movieinfolabel;
    	JTabbedPane tabs;
    	JList movieslist;
    	DefaultListModel model;
    	JScrollPane scrollmovieslist, scrollmovieinfotextarea;
    	Image moviesimage;
    	ImageIcon moviesicon;
    	Border moviesborder;
    	JTextArea movieinfotextarea;
     
      //*********************************************************
     
        public void init( )
        {
        	doFirst();
        	doMoviesTab( );
        	doMusicTab( );
        	doGamesTab( );
        	doAddTab( );
        	}
     
      //*********************************************************
     
        public void doFirst( )
        {
        	applet = new JPanel();
        	applet.setLayout(new BorderLayout());
        	this.setSize(new Dimension(600, 400));
     
        	UIManager.put("Tabbedpane.selected", new javax.swing.plaf.ColorUIResource(Color.red));
        	UIManager.put("Tabbedpane.contentAreaColor", new javax.swing.plaf.ColorUIResource(Color.red));
        	UIManager.put("Tabbedpane.background", new javax.swing.plaf.ColorUIResource(Color.red));
        	UIManager.put("Tabbedpane.shadow", new javax.swing.plaf.ColorUIResource(Color.red));
        	UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));
     
        	title = new JLabel("<html><font size=18>Media Collection Manager</font>");
        	tabs = new JTabbedPane(JTabbedPane.TOP);
     
        	title.setOpaque(true);
        	tabs.setOpaque(true);
     
        	//title.setBackground(Color.black);
        	//title.setForeground(Color.lightGray);
        	//tabs.setBackground(Color.black);
        	//tabs.setForeground(Color.lightGray);
     
        	applet.add(title, BorderLayout.NORTH);
        	applet.add(tabs, BorderLayout.CENTER);
        	add(applet);
        	}
     
      //*********************************************************
     
        public void doMoviesTab( )
        {
        	//Panels
        	JPanel moviespanel = new JPanel( );
        	JPanel himoviespanel = new JPanel();
        	JPanel lomoviespanel = new JPanel();
     
        	//Layouts
        	himoviespanel.setLayout(new GridLayout(1,2));
        	lomoviespanel.setLayout(new BorderLayout());
     
        	//Upper Components
        	model = new DefaultListModel();
        	movieslist = new JList(model);
        	scrollmovieslist = new JScrollPane(movieslist);
        	moviesimage = getImage(getCodeBase(), "placeholder.gif");
        	moviesicon = new ImageIcon(moviesimage);
        	moviesimagelabel = new JLabel(moviesicon);
     
        	//Lower Components
        	moviesborder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
        	movietitle = new JLabel("Movie Title");
        	movieinfolabel = new JLabel("Placeholder");
        	movieinfotextarea = new JTextArea("Placeholder Text. Placeholder Text. Placeholder Text. Placeholder Text. Placeholder Text.");
        	scrollmovieinfotextarea = new JScrollPane(movieinfotextarea);
        	moviedateacquired = new JLabel("Date Acquired");
     
        	//Cosmetic Stuff
        	movieinfotextarea.setEditable(false);
        	movieinfotextarea.setLineWrap(true);
        	movieinfotextarea.setWrapStyleWord(true);
        	movieinfolabel.setBorder(moviesborder);
        	movieinfolabel.setPreferredSize(new Dimension(250,150));
        	movieinfotextarea.setPreferredSize(new Dimension(250, 150));
     
        	//Colors
        	scrollmovieslist.setOpaque(true);
        	scrollmovieslist.setBackground(Color.black);
        	scrollmovieslist.setForeground(Color.lightGray);
        	moviesimagelabel.setOpaque(true);
        	moviesimagelabel.setBackground(Color.black);
        	moviesimagelabel.setForeground(Color.lightGray);
        	movietitle.setOpaque(true);
        	movietitle.setBackground(Color.black);
        	movietitle.setForeground(Color.lightGray);
        	movieinfolabel.setOpaque(true);
        	movieinfolabel.setBackground(Color.black);
        	movieinfolabel.setForeground(Color.lightGray);
        	scrollmovieinfotextarea.setOpaque(true);
        	scrollmovieinfotextarea.setBackground(Color.black);
        	scrollmovieinfotextarea.setForeground(Color.lightGray);
        	moviedateacquired.setOpaque(true);
        	moviedateacquired.setBackground(Color.black);
        	moviedateacquired.setForeground(Color.lightGray);
        	himoviespanel.setOpaque(true);
        	himoviespanel.setBackground(Color.black);
        	himoviespanel.setForeground(Color.lightGray);
        	lomoviespanel.setOpaque(true);
        	lomoviespanel.setBackground(Color.black);
        	lomoviespanel.setForeground(Color.lightGray);
        	moviespanel.setOpaque(true);
        	moviespanel.setBackground(Color.black);
        	moviespanel.setForeground(Color.lightGray);
     
        	//Add components to panels
        	himoviespanel.add(scrollmovieslist);
        	himoviespanel.add(moviesimagelabel);
        	lomoviespanel.add(movietitle, BorderLayout.NORTH);
        	lomoviespanel.add(movieinfolabel, BorderLayout.WEST);
        	lomoviespanel.add(scrollmovieinfotextarea, BorderLayout.CENTER);
        	lomoviespanel.add(moviedateacquired, BorderLayout.SOUTH);
     
        	//Add panels to tab
        	moviespanel.add(himoviespanel);
        	moviespanel.add(lomoviespanel);
     
        	//Add tab
        	//tabs.setBackgroundAt(1, Color.RED);
        	//tabs.setForegroundAt(1, Color.GREEN);
        	tabs.addTab("Movies", null, moviespanel, "Browse your movie collection");
        	}
     
      //*********************************************************
     
        public void doMusicTab( )
        {
        	JPanel musicpanel = new JPanel( );
     
        	//tabs.setBackgroundAt(2, Color.darkGray);
        	//tabs.setForegroundAt(2, Color.lightGray);
        	tabs.addTab("Music", null, musicpanel, "Browse your music collection");
        	}
     
      //*********************************************************
     
        public void doGamesTab( )
        {
        	JPanel gamespanel = new JPanel( );
     
        	//tabs.setBackgroundAt(3, Color.darkGray);
        	//tabs.setForegroundAt(3, Color.lightGray);
        	tabs.addTab("Games", null, gamespanel, "Browse your game collection");
        	}
     
      //*********************************************************
     
        public void doAddTab( )
        {
        	JPanel addpanel = new JPanel( );
     
        	//tabs.setBackgroundAt(4, Color.darkGray);
        	//tabs.setForegroundAt(3, Color.lightGray);
        	tabs.addTab("Add New", null, addpanel, "Add new items to your collection");
        	}
        }
    Last edited by shawksly; November 8th, 2011 at 11:06 PM.


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: I give up. Need help changing color of JTabbedPane selected Tab. I've Googled so

    I did find this with a quick search. I'll admit I don't know if it's accurate but I found this:

    jGuru: How do I change the color of the selected tab on a JTabbedPane?

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I give up. Need help changing color of JTabbedPane selected Tab. I've Googled so

    Thank you so much for trying, but unfortunately I tried that already. For some reason my code just doesn't respond.

Similar Threads

  1. How Do I Make Color Changing Buttons?
    By blurredvis0n in forum AWT / Java Swing
    Replies: 3
    Last Post: August 30th, 2011, 02:14 PM
  2. Need help with changing color of JOptionPane
    By jwise95 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 22nd, 2011, 09:49 AM
  3. Changing Panel Color with a ComboBox
    By bengregg in forum AWT / Java Swing
    Replies: 7
    Last Post: March 2nd, 2011, 10:04 PM
  4. changing the visited links color in JEditorpane
    By nasi in forum AWT / Java Swing
    Replies: 5
    Last Post: April 18th, 2010, 08:44 AM
  5. Change of color for selected text in AWT
    By venkyInd in forum AWT / Java Swing
    Replies: 2
    Last Post: April 9th, 2010, 03:51 AM