JTabbedPane selected tab size

Hello everybody;
I've created a JTabbedPane with JLabel on each tab and i want that the selected one size be larger than the other tabs.
The problem is that if I increase the size of the selected tab, all the others (inselected tabs) do so (they take the same size as the selected one) which is normal.
My need is to change this default behavior in order to fix the inselected tab size and increase the selected one to appear bigger
Thank you for your help

Hello,
- JDK 6
- MetalLookAndFeel
- JTabbedPane#getTabPlacement()==TOP
- Selected tab "width" only grow
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SelectedTabSizeTest{
  private static void addTab(JTabbedPane t, String title, Component c) {
    t.addTab(title, c);
    JLabel label = new JLabel(title, SwingConstants.CENTER);
    t.setTabComponentAt(t.getTabCount()-1, label);
  public JComponent makeUI() {
    JTabbedPane t = new JTabbedPane() {
      private void initTabWidth() {
        int tabCount  = getTabCount();
        if(tabCount==0) return;
        int bigger   = 50;
        int tabWidth = 30;
        int si = getSelectedIndex();
        for(int i=0;i<tabCount;i++) {
          JLabel l = (JLabel)getTabComponentAt(i);
          if(l==null) continue;
          int w = tabWidth+(si==i?bigger:0);
          int h = l.getPreferredSize().height;
          l.setPreferredSize(new Dimension(w, h));
      @Override public synchronized void repaint() {
        initTabWidth();
        super.repaint();
    t.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    addTab(t, "JTree",      new JScrollPane(new JTree()));
    addTab(t, "JTextArea",  new JScrollPane(new JTextArea("aaaa")));
    addTab(t, "Preference", new JScrollPane(new JTree()));
    addTab(t, "Help",       new JScrollPane(new JTextArea("bbbbbb")));
    t.setPreferredSize(new Dimension(320, 200));
    return t;
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      public void run() { createAndShowGUI(); }
  public static void createAndShowGUI() {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(new SelectedTabSizeTest().makeUI());
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

Similar Messages

  • JTabbedPane - Catching tab selection change

    I want to catch each tab selection change in my JTabbedPane.
    When I used ChangeListener, my program was unable to correctly
    indicate selected tab in some cases, i.e.:
    JTabbedPane contains two tabs: 0,1.
    Tab 0 was selected.
    Tab 0 was deleted.
    In this case JTabbedPane selects tab 1, but selected index remains
    unchanged and stateChanged is not called. How can I catch this?

    This trick is working, but you see, the problem is more
    complicated. The problem is that stateChanged() doesn't work
    when index remains unchanged. This is also true for insertTab().
    Both insertTab() and removeTabAt() (and maybe smth. else) causes this problem.
    Maybe, possible solution will be to override some method of
    JTabbedPane, responsible for activating a tab like this...?
    tabbedPane = new JTabbedPane {
        activateTab(...) {
            super.activateTab(...);
            firePropertyChange(...);
    }But what is the methods prototype and can it be overriden
    at all??
    In the deep sources of swing :) I've found such tricks:
    In JTabbedPane.insertTab():accessibleContext.firePropertyChange(
        AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
        null, component);In JTabbedPane.removeTabAt():accessibleContext.firePropertyChange(
        AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
        component, null);I'm almost convinced that this is the point. But!
    I've never worked with Accesibility :(
    And I couldn't find out what to do having only swing sources.
    Need help.

  • Changing Colors of selected tab in JTabbedPane.

    Do someone has some code that can show how to
    change the color of the selected tab with JTabbedPane.
    I can change the other tabs colors with setBackground and setForeground, setBackgroundAt........ but it is the selected
    tab that will not change from the default grey color.
    thanks

    try this code, it works.
    public class TabBackgroundChange extends JFrame {
    private JTabbedPane tabPane = null;
    public static final Color selTabColor = Color.red;
    Color nonSelectedTabColor = null;
    public TabBackgroundChange() {
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    catch(Exception ex) {
    ex.printStackTrace();
    tabPane = new JTabbedPane();
    tabPane.add("One", new JPanel());
    tabPane.add("Two", new JPanel());
    tabPane.add("Three", new JPanel());
    this.getContentPane().add(tabPane);
    this.setSize(200, 200);
    this.setVisible(true);
    tabPane.addChangeListener(new TabChangeListener());
    tabPane.setSelectedIndex(1);
    tabPane.setSelectedIndex(0);
    public static void main(String[] args) {
    TabBackgroundChange tabBackgroundChange1 = new TabBackgroundChange();
    private class TabChangeListener implements ChangeListener {
    public void stateChanged(ChangeEvent ce) {
    int iSelTab = tabPane.getSelectedIndex();
    Color unSelectedBackground = tabPane.getBackgroundAt(iSelTab);
    for(int i=0; i<tabPane.getTabCount(); i++) {
    tabPane.setBackgroundAt(i, unSelectedBackground);
    tabPane.setBackgroundAt(iSelTab, Color.red);
    }

  • When does a JTabbedPane set the size of the component inside a tab?

    I would like to know how big a component inside a tab is directly after I've added it to a tab in a JTabbedPane.
    I thought once I've "added" a component via the JTabbedPane.add(String, Component) method, the Component would be realized with correct sizes.
    Where or when should I request the information about how big a component has become inside a tab??
    Example:
    1. "Add" a tab via the menu.
    2. Notice that the size of the panel has not changed even though we see it on the screen.
    -Js
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    public class TabbedPaneShowingTest extends JFrame
         //GUI
         private JTabbedPane tabbedPane;
              private JPanel tabPanel;
         //MENU
         private JMenuBar mainMenuBar;
              private JMenu actionMenu;
                   private JMenuItem addTabMenuItem;
         public TabbedPaneShowingTest()
              this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
              this.setContentPane(getTabbedPane());
              this.setJMenuBar(getMainMenuBar());
              this.pack();
              this.setVisible(true);
         //GUI
         private JTabbedPane getTabbedPane()
              if(tabbedPane == null)
                   tabbedPane = new JTabbedPane();
                   tabbedPane.setPreferredSize(new Dimension(100,100));
              return tabbedPane;
         private JPanel getTabPanel()
              if(tabPanel == null)
                   tabPanel = new JPanel();
                   tabPanel.setBackground(Color.GREEN);
              return tabPanel;
         //MENU
         private JMenuBar getMainMenuBar()
              if(mainMenuBar == null)
                   mainMenuBar = new JMenuBar();
                   mainMenuBar.add(getActionMenu());
              return mainMenuBar;
         private JMenu getActionMenu()
              if(actionMenu == null)
                   actionMenu = new JMenu("Action");
                   actionMenu.add(getAddLineMenuItem());
              return actionMenu;
         private JMenuItem getAddLineMenuItem()
              if(addTabMenuItem == null)
                   addTabMenuItem = new JMenuItem("Add Tab");
                   addTabMenuItem.addActionListener(new ActionListener()
                        public void actionPerformed(ActionEvent e)
                             System.out.println("BEFORE TAB SIZE: " + getTabPanel().getWidth() + "," + getTabPanel().getHeight());
                             getTabbedPane().add("Tab",getTabPanel());
                             System.out.println("AFTER TAB SIZE: " + getTabPanel().getWidth() + "," + getTabPanel().getHeight());
              return addTabMenuItem;
         public static void main(String args[])
              new TabbedPaneShowingTest();
    }

    Once again... a little experimenting is a good thing. Just use SwingUtilities.InvokeLater() to retrieve the proper size.
    -Js
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    import javax.swing.SwingUtilities;
    public class TabbedPaneShowingTest extends JFrame
         //GUI
         private JTabbedPane tabbedPane;
              private JPanel tabPanel;
         //MENU
         private JMenuBar mainMenuBar;
              private JMenu actionMenu;
                   private JMenuItem addTabMenuItem;
         public TabbedPaneShowingTest()
              this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
              this.setContentPane(getTabbedPane());
              this.setJMenuBar(getMainMenuBar());
              this.pack();
              this.setVisible(true);
         //GUI
         private JTabbedPane getTabbedPane()
              if(tabbedPane == null)
                   tabbedPane = new JTabbedPane();
                   tabbedPane.setPreferredSize(new Dimension(100,100));
              return tabbedPane;
         private JPanel getTabPanel()
              if(tabPanel == null)
                   tabPanel = new JPanel();
                   tabPanel.setBackground(Color.GREEN);
              return tabPanel;
         //MENU
         private JMenuBar getMainMenuBar()
              if(mainMenuBar == null)
                   mainMenuBar = new JMenuBar();
                   mainMenuBar.add(getActionMenu());
              return mainMenuBar;
         private JMenu getActionMenu()
              if(actionMenu == null)
                   actionMenu = new JMenu("Action");
                   actionMenu.add(getAddLineMenuItem());
              return actionMenu;
         private JMenuItem getAddLineMenuItem()
              if(addTabMenuItem == null)
                   addTabMenuItem = new JMenuItem("Add Tab");
                   addTabMenuItem.addActionListener(new ActionListener()
                        public void actionPerformed(ActionEvent e)
                             System.out.println("BEFORE TAB SIZE: " + getTabPanel().getWidth() + "," + getTabPanel().getHeight());
                             getTabbedPane().addTab("Tab",getTabPanel());
                             SwingUtilities.invokeLater(new Runnable()
                                  public void run()
                                       System.out.println("AFTER TAB SIZE: " + getTabPanel().getWidth() + "," + getTabPanel().getHeight());
              return addTabMenuItem;
         public static void main(String args[])
              new TabbedPaneShowingTest();
    }

  • Why isn't the selected tab title bold in JTabbedPane? How can I make it be?

    The selected tab title of JTabbedPanel is not bold. Is there a simple way to set it to be bold when a tab is selected? Thanks in advance.

    1. Simply use the HTML code in it's text like '<html><b>NameOfThisTab</b></html>'.
    2. Extend the JTabbedPane and fine-tune the font it uses.

  • How to insure selected tabs are visible in JTabbedPane

    Hello all,
    How can you insure that the selected tab in a JTabbedPane is visible.
    Here is the code:
    import javax.swing.*;
    import java.awt.*;
    public class TabbedPaneTest extends JTabbedPane implements Runnable
    public TabbedPaneTest()
    super(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    } // end TabbedPaneTest constructor
    public void run ()
    for (int i = 1; i <= 10; i ++)
    try
    this.addTab(Integer.toString(i), createDefaultPanel (i));
    this.getModel().setSelectedIndex(i - 1);
    Thread.sleep(3000);
    } // end try block
    catch (Exception e)
    e.printStackTrace();
    } // end catch block
    } // end for loop
    } // end run method
    private JPanel createDefaultPanel (int index)
    JPanel defaultPanel = new JPanel ();
    defaultPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLoweredBevelBorder(), Integer.toString(index)));
    return defaultPanel;
    } // end createDefaultPanel method
    public static void main (String args [])
    JFrame frame = new JFrame ();
    TabbedPaneTest tpt = new TabbedPaneTest ();
    frame.getContentPane().add(tpt);
    frame.setSize(200, 200);
    Thread newThread = new Thread (tpt);
    newThread.start();
    frame.setVisible(true);
    } // end main method
    } // end TabbedPaneTest class
    I've crated a JTabbedPane with the tabLayoutPolicy set to JTabbedPane.SCROLL_TAB_LAYOUT.
    If I add enough tabs the scroll buttons appear but the newly adde tab is hidden behind them,
    even though I have set the selection index to the added tab. The content of the panel associated
    with the tab is visible but the tab itself is hidden.
    So the selected tab is hidden behind the scroll buttons.
    Any one know how to insure that if a tab is selected it is visible to the user.
    Thanks

    This is an interesting question so I tried it out. After some poking around to see how Swing does this for mouse clicking (try setting things up so that a tab is only partially visible and then click on the visable part - notice how the whole tab is scrolled into view) I found this:    /**
         * This inner class is marked "public" due to a compiler bug.
         * This class should be treated as a "protected" inner class.
         * Instantiate it only within subclasses of BasicTabbedPaneUI.
        public class TabSelectionHandler implements ChangeListener {
            public void stateChanged(ChangeEvent e) {
                JTabbedPane tabPane = (JTabbedPane)e.getSource();
                tabPane.revalidate();
                tabPane.repaint();
                if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) {
                    int index = tabPane.getSelectedIndex();
                    if (index < rects.length && index != -1) {
                        tabScroller.tabPanel.scrollRectToVisible(rects[index]);
        }Which is called when the selected tab changes. The member theScroller is a private inner class that handles the scrolling tabs. The call to scrollRectToVisible is executed for each of your new tabs. Sometimes when I stopped in the debugger and then continued things worked and your new tab scrolled into view.
    So I tried putting your code into a Runnable class and invoked it later:          final int newIndex = i;
              SwingUtilities.invokeLater (new Runnable ()  {
                   public void run ()  {
                        addTab(Integer.toString(newIndex), createDefaultPanel (newIndex));
                        getModel().setSelectedIndex(newIndex - 1);
              });But that did not work. That is as far as I got so far and I have to stop now. Perhaps this can inspire someone else to a solution.
    IL
    PS. I first tried Rammensee's solution and it did not work.
    Rammensee, you said you hoped you had it right - perhaps you are close.

  • JTabbedPane - BOLD selected tab title text.

    I want to BOLD the selected tab's title text while keeping the unselected tabs' title text in normal font. Anyone know how to achieve this effect?

    I think the simplest  way is to use JTabbedPane.setTabComponentAt, add your own labels, add a ChangeListener to the JTabbedPane and change the labels fonts when tab selection changes.

  • Updating a JTabbedPane's selected tab color dynamically

    Hi
    I have set the selected tab color for my JTabbedPane
    using:
    UIManager.put("TabbedPane.selected", Color.RED);Now I would like to change the color dynamically to green.
    However, just calling:
    UIManager.put("TabbedPane.selected", Color.GREEN);doesn't work.
    It seems that if the JTabbedPane is visible while I change the color through the UIManager, it has no effect.
    On the other hand, all the other JTabbedPanes in my application (which are not visible - in hidden dialogs), are effected.
    How can I effect ALL the JTabbedPanes in my application at the same time?

    Try to call
    SwingUtilities.updateComponentTreeUI(selectedPane);
    best regards
    Stas

  • JTabbedPane Tab Size & Spacing

    I have set up a JTabbedPane and have put icons in instead of text for the tabs, the icons I've designed are supposed to take the place of the tab look, I already have the tabs transparent. I was wondering if anyone could help me with tab size and tab spacing because my custom tabs are WAY too far apart. Thanks in advance.

    I figured it out, I made a custom UI class that extends BasicTabbedUI and set the constraints that I desired.

  • Stopping right click selecting tab in JTabbedPane

    Hello all,
    This may be a really simple thing + I'm probably being thick, but is there a way to prevent a right click changing the selected tab on a JTabbedPane.
    I tried consuming the MouseEvent, but that didn't seem to work. Couldn't find an answer anywhere else in the forums & couldn't see anything in the JavaDoc that looked as if it would help.
    Answers on a postcard please......
    RT

    You might be able to extend JTabbedPane and override setSelectedIndex().
    I had to do this to work around a focus issue I had.
      This class extends JTabbedPane to correct a problem where it doesn't
      request focus when clicked on.
    import java.awt.*;
    import javax.swing.*;
    public class MyJTabbedPane extends JTabbedPane {
      public void setSelectedIndex(int index) {
        Component comp = KeyboardFocusManager.
            getCurrentKeyboardFocusManager().getFocusOwner();
        //  if  no tabs are selected
        // -OR- the current focus owner is me
        // -OR- I request focus from another component and get it
        // then proceed with the tab switch
        boolean noTabSelected = getSelectedIndex()==-1;
        boolean hasFocus = requestFocus(false);
        boolean compIsMe = comp==this;
        if(noTabSelected || hasFocus || compIsMe) {
          super.setSelectedIndex(index);
    }

  • How to change tab size on Jtabbedpane?

    Hi,guys,
    I want to set an icon on each tab,so my code is as follows:
    ImageIcon projectIcon= createImageIcon("bleumbuddy/workorder-tab2-active.gif");
    jTabbedPane1.addTab("",projectIcon,jPanel7);
    But the tab size is bigger than the img's size,How can I change it to the same as the image?
    thanx a lot .
    Best Regards
    Dragon

    Hi,guys,
    I want to set an icon on each tab,so my code is as follows:
    ImageIcon projectIcon= createImageIcon("bleumbuddy/workorder-tab2-active.gif");
    jTabbedPane1.addTab("",projectIcon,jPanel7);
    But the tab size is bigger than the img's size,How can I change it to the same as the image?
    thanx a lot .
    Best Regards
    Dragon

  • Issue with F110 - FREE SELECTION TAB.

    Hi All,
    I am facing one problem for updating the FREE SELECTION TAB for FIELD NAME and its corresponding value. For this update I am using BDC.
    If I create the proposal manually then the values get display after saving the proposal entry. But if I do the same through recording, it does display the message on status bar as "Details have been saved for the run".
    Any help is appreciated.
    Thanks,
    Atul

    Following is the recording that works in 4.7 but doesnt work in ECC 6.0 version.
    The values under free selection gets clear in ECC 6.0
    Can anyone please help.. !!!
    Thanks in advance..
    Atul
    report ZF110_NEW
           no standard page heading line-size 255.
    include bdcrecx1.
    start-of-selection.
    perform open_group.
    perform bdc_dynpro      using 'SAPF110V' '0200'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'F110V-LAUFI'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=SEL'.
    perform bdc_field       using 'F110V-LAUFD'
                                  '01/22/2007'.
    perform bdc_field       using 'F110V-LAUFI'
                                  '2712'.
    perform bdc_dynpro      using 'SAPF110V' '0200'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=SICH'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'F110V-LIST1(02)'.
    perform bdc_field       using 'F110V-TEXT1(01)'
                                  'BKPF-BELNR'.
    perform bdc_field       using 'F110V-TEXT1(02)'
                                  'LFA1-LAND1'.
    perform bdc_field       using 'F110V-LIST1(01)'
                                  '1000001'.
    perform bdc_field       using 'F110V-LIST1(02)'
                                  'PA'.
    perform bdc_dynpro      using 'SAPF110V' '0200'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '/EBCK'.
    perform bdc_dynpro      using 'SAPF110V' '0200'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '/EBCK'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'F110V-LAUFD'.
    perform bdc_transaction using 'F110'.
    perform close_group.

  • Powershell ISE – change indent/tab size + keep tabs

    Anyway to change indent/tab size in Powershell ISE?
    Something simple like in Visual studio IDE:
    Tab size 2
    Indent size 2
    Keep tabs

    Figured I'd share the changes I made to NoSimDash's above code. I actually wrote this not long after he posted his reply, but decided not to post it after I settled on taking the cheap, hacky timer route. (Originally I was looking to have the process triggered
    by an event when the user changed tabs)
    Anyways, over the last two years it's been pretty stable, so I thought I'd share on the off-chance that someone goes looking for this functionality again.
    $psISE.Options.ShowOutlining = $true
    $psISE.Options.ShowDefaultSnippets = $true
    $psISE.Options.ShowIntellisenseInScriptPane = $true
    $psISE.Options.ShowIntellisenseInConsolePane = $true
    Set-Variable -Option AllScope -Name OptionSetter -Value (&{
    $ClassName = 'IndentFixer'
    $Namespace = 'ISEHijack'
    Add-Type @"
    internal class _Option<TValue>
    public _Option(string key, TValue value)
    Key = key;
    Value = value;
    public Object[] Params { get { return new object[] { Key, Value }; } }
    public string Key { get; private set; }
    public TValue Value { get; private set; }
    internal static object[] Opt<TVal>(string key, TVal value)
    return new _Option<TVal>(key, value).Params;
    internal static readonly object[][] NewOpts = {
    Opt<bool>("Adornments/HighlightCurrentLine/Enable", false),
    Opt<int>("Tabs/TabSize", 4),
    Opt<int>("Tabs/IndentSize", 4),
    Opt<bool>("Tabs/ConvertTabsToSpaces", false),
    Opt<bool>("TextView/UseVirtualSpace", false),
    Opt<bool>("TextView/UseVisibleWhitespace", true)
    internal void SetOpts()
    foreach(object[] args in NewOpts) {
    Setter.Invoke(Options, args);
    public MethodInfo Setter { get; set; }
    public object Options { get; set; }
    public Dispatcher EditorDispatcher { get; set; }
    public List<Action> Actions { get; private set; }
    public ${ClassName}()
    Actions = new List<Action>();
    Actions.Add(SetOpts);
    public void Dispatch(Dispatcher dispatcher)
    DispatcherFrame frame = new DispatcherFrame();
    dispatcher.BeginInvoke(DispatcherPriority.Normal, new DispatcherOperationCallback(ExitFrames), frame);
    Dispatcher.PushFrame(frame);
    private object ExitFrames(object f){
    DispatcherFrame frame = ((DispatcherFrame)f);
    // foreach(Action action in Actions) {
    // action.Invoke();
    // Actions.Clear();
    foreach(object[] args in NewOpts) {
    Setter.Invoke(Options, args);
    frame.Continue = false;
    return null;
    "@ -Name $ClassName `
    -NameSpace $Namespace `
    -UsingNamespace System.Windows.Forms,System.Windows.Threading,System.Reflection,Microsoft.VisualStudio.Text.EditorOptions.Implementation,System.Collections.Generic `
    -ReferencedAssemblies WindowsBase,System.Windows.Forms,Microsoft.PowerShell.Editor
    return `
    "${Namespace}.${ClassName}" |
    Add-Member -Type NoteProperty -Name Namespace -Value $Namespace -Passthru |
    Add-Member -Type NoteProperty -Name ClassName -Value $ClassName -Passthru
    [System.Reflection.BindingFlags] $NonPublicFlags = [System.Reflection.BindingFlags] 'NonPublic,Instance'
    filter Expand-Property
    PARAM(
    [Alias('Property')]
    [ValidateNotNullOrEmpty()]
    [Parameter(Mandatory, Position=0)]
    [String] $Name
    $_ | Select-Object -ExpandProperty $Name | Write-Output
    function Get-IsePrefs
    PARAM(
    [Parameter(Mandatory, Position=1)]
    [ValidateNotNullOrEmpty()]
    [string] $Key
    $oEditor = $psISE.CurrentFile.Editor
    $tEditor = $oEditor.GetType()
    $tEditor.GetProperty('EditorOperations', $NonPublicFlags).GetMethod.Invoke($oEditor, $null).Options | `
    Expand-Property GlobalOptions | `
    Expand-Property SupportedOptions | `
    Select-Object -Property Key,ValueType,DefaultValue | `
    Write-Output
    function Comment-Selection
    $output = ''
    $psISE.CurrentFile.Editor.SelectedText.Split("`n") | ForEach-Object -Process { $output += "# " + [string]$_ + "`n" }
    $psISE.CurrentFile.Editor.InsertText($output)
    function Fix-EditorIndentation
    PARAM(
    [Alias('ISEEditor')][ValidateNotNull()]
    [Parameter(Mandatory, ValueFromPipeline, Position=1)]
    [Microsoft.PowerShell.Host.ISE.ISEEditor]
    $Editor
    $EditorType = $Editor.GetType()
    $SetterInstance = New-Object -TypeName $OptionSetter
    $SetterInstance.Options = $EditorType.GetProperty('EditorOperations', $NonPublicFlags).GetMethod.Invoke($Editor, $null).Options
    $Dispatcher = $EditorType.GetProperty('EditorViewHost', $NonPublicFlags).GetMethod.Invoke($Editor, $null).Dispatcher
    $SetterInstance.Setter = $SetterInstance.Options.GetType().GetMethod('SetOptionValue', [type[]]@([string],[object]))
    $SetterInstance.Dispatch($Dispatcher)
    function Fix-IseIndentation
    [Microsoft.Windows.PowerShell.Gui.Internal.MainWindow] $ISEWindow = (Get-Host | Select-Object -ExpandProperty PrivateData | Select-Object -ExpandProperty Window)
    [Microsoft.Windows.PowerShell.Gui.Internal.RunspaceTabControl] $RSTabCtrl = $ISEWindow.Content[0].Children[2]
    [Microsoft.PowerShell.Host.ISE.PowerShellTab] $PSTab = $RSTabCtrl.Items[0]
    $PSTab.Files | Select-Object -ExpandProperty Editor | Fix-EditorIndentation
    function Invoke-ISEFunction
    PARAM(
    [Parameter(Mandatory, Position=1)]
    [Action] $ScriptBlock
    $ISEWindow = $(Get-Host | Select-Object -ExpandProperty PrivateData | Select-Object -ExpandProperty Window)
    return $ISEWindow.Dispatcher.Invoke($ScriptBlock)
    function Fix-IndentationForAll
    $psISE.PowerShellTabs | Select-Object -ExpandProperty 'Files' | Select-Object -ExpandProperty 'Editor' | Fix-EditorIndentation
    # Startup
    function New-Timer
    PARAM(
    [Alias('Handler')]
    [Parameter(Position=0, Mandatory=$true)]
    $Action,
    [Double]
    [Parameter(Mandatory=$false)]
    $Interval = 50,
    [Boolean]
    [Parameter(Mandatory=$false)]
    $AutoReset = $true
    [System.Timers.Timer] $oTimer = New-Object -TypeName System.Timers.Timer($Interval)
    $ElapsedEvent = Register-ObjectEvent -InputObject $oTimer -EventName 'Elapsed' -Action $Action
    $oTimer.AutoReset = $AutoReset
    return $oTimer
    $(New-Timer {
    Fix-IndentationForAll
    } -Interval 100 -AutoReset $true).Start()

  • JTabbedPane selection color

    is it possible to change the default JTabbedPane selection color? (light gray)
    It doesnt seem to give you the ability to set a Renderer

    If altering the UI for your JTabbedPane is an option for you then this becomes pretty easy, just override the "paintTabBackground" method of BasicTabbedPaneUI. This isn't an option for a lot of people though... since that would pretty much limit you to one UI.
    Otherwise you will have set the background of the tab manually... the following code is an example of how to do this... unfortunatly... MetalTabbedPaneUI overrides the paintTabBackground method and DOESN'T use the manual backgrounds for selected tabs, it ALWAYS uses the default selectedColor from the UIManager... looks like an oversite to me... anyway... this code works fine with the Windows Look and Feel...
    import javax.swing.*;
    import javax.swing.event.ChangeListener;
    import javax.swing.event.ChangeEvent;
    import java.awt.*;
    * <pre>
    * SBTabbedPane
    * </pre>
    public class SBTabbedPane extends JTabbedPane {
         private Color tback;
         private int tsel = -1;
         private Color sback;
         public SBTabbedPane() {
              addChangeListener(new ChangeListener() {
                   public void stateChanged(ChangeEvent e) {
                        redoback();
         public void setSelectionBackground(Color c) {
              sback = c;
              redoback();
         private void redoback() {
              if (tsel >= 0) {
                   setBackgroundAt(tsel, tback);
              int i = getSelectedIndex();
              if (sback != null && i >= 0) {
                   tback = getBackgroundAt(i);
                   tsel = i;
                   System.out.println("SET BACK: " + tsel + ": " + sback);
                   setBackgroundAt(tsel, sback);
         public static final void main(String[] args) {
              try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              } catch (Exception e) {}
              SBTabbedPane test = new SBTabbedPane();
              test.setSelectionBackground(new Color(255,0,0));
              test.add("Tab 1", new JLabel("HELLO"));
              test.add("Tab 2", new JLabel("WORLD"));
              JFrame testframe = new JFrame("Test Window");
              testframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              testframe.getContentPane().setLayout(new BorderLayout(0, 0));
              testframe.getContentPane().add(test);
              testframe.pack();
              testframe.setVisible(true);
    }Hope this helps a little...
    Josh Castagno
    http://www.jdc-software.com

  • Setting the Font of Selected Tab in JTabbed Pane

    Hi,
    i have A JTabbedPane , I want to set the font of the selected tab to be bold. Can anyone please tell me how can i do that...
    waiting for reply ,
    Bye
    Sanjeev

    http://search.java.sun.com/search/java/index.jsp?qp=&nh=10&qt=%2BJTabbedPane+%2Btab+%2Bfont&col=javaforums

Maybe you are looking for

  • How to reformat Ipod Nano 5th gen when not recognized by Windows or iTunes?

    I've done all the steps on the site to correct this problem up until the reformatiing part except I tried to update the driver software but Windows says that it encounters an error when trying to install the new software. So after going through the s

  • Mail going to Trash Folder?

    Almost all my mail is going straight to the trash folder on my iPad? Please Help?

  • Can you set a max size for a folder on a file server

    I've got a G5 Xserve that I'm using as a file server running 10.3.9. I need more space on my array so I bought bigger drives and will move the data to the new, larger array. For the health of my drives, I want my array to maintain at least 10% free s

  • Connecting c5 to sony car unit!

    Hi all, when I used to connect my old nokia 6300 to my car radio/cd unit (sony 6000 cd) via bluetooth I used to have the call list (as stored in the phone by name displayed in, out, missed etc on the car head unit screen when the phone button was pre

  • PLEASE help - NoClassDefFoundError

    Yes - I know this topic has come up MANY MANY times. Matter of fact looking at the postings - did get some issues working that was having problems with. The program CooperClient.CooperClient works with no problems with the following: java -classpath