How to create multiple tabs under the editing part of the opened file.

已回答

I want to create more than 3 multiple tabs under the editing part of the opened file.

Like this

 

.

Now EditorProvider class

class MyFileEditorProvider : AsyncFileEditorProvider, DumbAware {
  override fun createEditorAsync(@NotNull project: Project, @NotNull virtualFile: VirtualFile): Builder {
    return object : Builder() {
      override fun build(): FileEditor {
        val values = createValue()

        return MyFileEditor(MyComponent("01", "01", values).toComponent())
      }
    }
  }
  ...
}
0

Hi,

As far as I know, you have to implement as many FileEditorProviders as editor tabs you want to see under the editor.

1

Sorry, I forgot to mention toComponent.
I got it working by doing this.

 

// MyComponent.kt
import com.intellij.ui.components.JBTabbedPane

// MySubComponent.kt
import com.intellij.ui.components.JBScrollPane
import com.intellij.ui.table.JBTable
import javax.swing.*
import javax.swing.table.DefaultTableModel

class MyComponent(private val components: List<MySubComponent>) {
  fun toComponent(): JBTabbedPane {
    val pane = JBTabbedPane(JBTabbedPane.BOTTOM)
    components.forEach { it: MySubComponent -> pane.add(it.sheetName, it.toComponent()) }
    return pane
  }
}

class MySubComponent {
  fun toComponent(): JComponent {
    val table = JBTable(DefaultTableModel(col + 1, row + 1))
    table.autoResizeMode = JBTable.AUTO_RESIZE_OFF
    cells.forEach {
      table.setValueAt(it.getValue(), it.getRow(), it.getColumn())
    }
    return JBScrollPane(table)
  }
}
1

请先登录再写评论。