Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

74
LINES

< > BotCompany Repo | #1035165 // BUGGY JExtendedTabbedPane - JTabbedPane where you can place a component in the free space beside the tabs

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (11380L) is out of date.

// Note: There seems to be some extra space below the tabs
// when using JTattoo. FlatLAF works fine.
// TODO: changing tabs at runtime, event handling etc.
sclass JExtendedTabbedPane is Swingable {
  JTabbedPane tabs;
  new L<Component> components;
  SingleComponentPanel scpBesideTabs = scp();
  SingleComponentPanel scpPage = scp();
  
  *(JTabbedPane _tabs) swing {
    tabs = _tabs != null ? _tabs : jtabs();
    int n = tabCount(tabs);
    for i to n: {
      components.add(tabs.getComponentAt(i));
      tabs.setComponentAt(i, emptyPage());
    }
      
    onTabSelectedAndNow(tabs, l0 updatePage);
  }
  
  void updatePage {
    int idx = getSelectedIndex();
    var c = get(components, idx);
    //printVars("JExtendedTabbedPane.updateTabs", +idx, +c);
    scpPage.set(c);
  }
  
  // Something with minimum size 0
  Component emptyPage() { ret verticalStrut(0); }
  
  cachedVisual
    northAndCenter(centerAndEastWithMargin(
      tabs, scpBesideTabs),
      scpPage);
    
  selfType setComponentBesideTabs(Component c) {
    scpBesideTabs.set(c);
    this;
  }
  
  int getSelectedIndex() {
    ret tabs.getSelectedIndex();
  }
  
  void setComponentAt(int i, Component c) {
    components.set(i, c);
    if (getSelectedIndex() == i) updatePage();
  }
  
  Component getComponentAt(int i) {
    ret components.get(i);
  }
  
  Component getTabComponentAt(int i) {
    ret tabs.getTabComponentAt(i);
  }
  
  void add(S title, Component c) {
    components.add(c);
    tabs.add(title, emptyPage());
  }
  
  int getTabCount() {
    ret tabs.getTabCount();
  }
  
  void setTitleAt(int i, S title) {
    tabs.setTitleAt(i, title);
  }
  
  void setSelectedIndex(int i) {
    tabs.setSelectedIndex(i);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035165
Snippet name: BUGGY JExtendedTabbedPane - JTabbedPane where you can place a component in the free space beside the tabs
Eternal ID of this version: #1035165/26
Text MD5: f8c81557c5b945f5584ed4a8ec6f13e6
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-09-21 16:47:51
Source code size: 1792 bytes / 74 lines
Pitched / IR pitched: No / No
Views / Downloads: 70 / 189
Version history: 25 change(s)
Referenced in: [show references]