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

86
LINES

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

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

Transpiled version (12335L) is out of date.

1  
// Not buggy anymore?
2  
3  
// Note: There seems to be some extra space below the tabs
4  
// when using JTattoo. FlatLAF works fine.
5  
// TODO: changing tabs at runtime, event handling etc.
6  
7  
// Need latest chain:
8  
// need latest JExtendedTabbedPane jExtendedTabs setTab setTabTitle onTabSelectedAndNow addTab selectTab countTabs indexOfSelectedTab tabCount selectedTabIndex.
9  
10  
sclass JExtendedTabbedPane is Swingable {
11  
  JTabbedPane tabs;
12  
  new L<Component> components;
13  
  SingleComponentPanel scpBesideTabs = scp();
14  
  SingleComponentPanel scpPage = scp();
15  
  settable bool verbose;
16  
  
17  
  *(JTabbedPane _tabs) swing {
18  
    tabs = _tabs != null ? _tabs : jtabs();
19  
    int n = tabCount(tabs);
20  
    for i to n: {
21  
      var c = tabs.getComponentAt(i);
22  
      c.setVisible(true);
23  
      components.add(c);
24  
      tabs.setComponentAt(i, emptyPage());
25  
    }
26  
      
27  
    onTabSelectedAndNow(tabs, l0 updatePage);
28  
  }
29  
  
30  
  void updatePage {
31  
    int idx = getSelectedIndex();
32  
    var c = get(components, idx);
33  
    if (verbose) printVars("JExtendedTabbedPane.updateTabs", +idx, +c);
34  
    scpPage.set(c);
35  
  }
36  
  
37  
  // Something with minimum size 0
38  
  Component emptyPage() { ret verticalStrut(0); }
39  
  
40  
  cachedVisual vertical()
41  
    ? westAndCenter(centerAndSouthWithMargin(tabs, scpBesideTabs), wrapPage(scpPage))
42  
    : northAndCenter(centerAndEastWithMargin(tabs, scpBesideTabs), wrapPage(scpPage));
43  
    
44  
  swappable JComponent wrapPage(JComponent page) { ret page; }
45  
    
46  
  selfType setComponentBesideTabs aka setComponentBelowTabs(Component c) {
47  
    scpBesideTabs.set(c);
48  
    this;
49  
  }
50  
  
51  
  int getSelectedIndex() {
52  
    ret tabs.getSelectedIndex();
53  
  }
54  
  
55  
  void setComponentAt(int i, Component c) {
56  
    components.set(i, c);
57  
    if (getSelectedIndex() == i) updatePage();
58  
  }
59  
  
60  
  Component getComponentAt(int i) {
61  
    ret components.get(i);
62  
  }
63  
  
64  
  Component getTabComponentAt(int i) {
65  
    ret tabs.getTabComponentAt(i);
66  
  }
67  
  
68  
  void add(S title, Component c) {
69  
    components.add(c);
70  
    tabs.add(title, emptyPage());
71  
  }
72  
  
73  
  int getTabCount() {
74  
    ret tabs.getTabCount();
75  
  }
76  
  
77  
  void setTitleAt(int i, S title) {
78  
    tabs.setTitleAt(i, title);
79  
  }
80  
  
81  
  void setSelectedIndex(int i) {
82  
    tabs.setSelectedIndex(i);
83  
  }
84  
  
85  
  bool vertical() { ret tabs.getTabPlacement() == JTabbedPane.LEFT; }
86  
}

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: JExtendedTabbedPane - JTabbedPane where you can place a component in the free space beside the tabs
Eternal ID of this version: #1035165/34
Text MD5: af6f6cc7337119548daedbc1fc48ae9c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-01-31 21:41:54
Source code size: 2354 bytes / 86 lines
Pitched / IR pitched: No / No
Views / Downloads: 235 / 424
Version history: 33 change(s)
Referenced in: [show references]