jtabbedpane

Closeable JTabbedPane - alignment of the close button

人盡茶涼 提交于 2019-12-19 18:15:24
问题 I have implemented my own closeable JTabbedPane (essentially following advice from here - by extending JTabbedPane and overriding some methods and calling setTabComponentAt(...)). It works perfectly except one thing - when there are too many tabs to fit on one row (when there are 2 or more rows of tabs), the cross button/icon is not aligned to the right of the tab but it remains next to the tab title, which looks ugly. I've tried the demo from Java tutorials and it suffers from the same

Tabs at fixed positions in JTabbedPane or in one row

我的未来我决定 提交于 2019-12-19 07:54:05
问题 In our application that has a JTabbedPane with unlimited tabs, when the width of the tabs exceeds the tabbed pane's width, the tabs start wrapping into several rows. When you then click on a tab in one of the upper rows, the complete row comes down and to the foreground. For users who click around between several tabs, it's highly confusing as it's not possible to keep track of the tab order. How can I either - nail the tabs to fixed positions while bringing their contents to the front

JTabbedPane ChangeListener

巧了我就是萌 提交于 2019-12-18 12:45:13
问题 I need to detect when the selected tab changes, and get its index. The following code works, but it fires the println as many times as the amount of tabs currently loaded: tabbedPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("Tab: " + tabbedPane.getSelectedIndex()); // Prints the string 3 times if there are 3 tabs etc } }); What is the correct way of doing this? Thank you in advance. 回答1: By JDK 6 Update 26 (Windows 7 64-Bit), I only

Insert JFrame into a Tab in Swing

♀尐吖头ヾ 提交于 2019-12-18 09:41:53
问题 I Have an already given JFrame frame , that I want to show it (insert it) into a tab of JTabbedPane , but that was not possible explicitely like that: frame = new JFrame(); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainTabs.addTab("Editor", null, frame, null); And the error was: java.lang.IllegalArgumentException: adding a window to a container I tried some solutions like to insert the frame into a JPanel but also in vain. I have the idea to

How does one make a component in the .CENTER of a Borderlayout occupy all center space and resize with the app?

别来无恙 提交于 2019-12-18 08:54:39
问题 My app/JFrame, using Borderlayout, has a toolbar at the top or north, a statusbar at the bottom or south and a JPanel.JTabbedPane.JScrollPane.JTable in the center. The JPanel is always a fixed size which is roughly adjustable using the various set*Size() methods applied in various combinations to the various components. But it's always a fixed size and always has east and west gaps. The north and south components stay fixed height and resize horizontally as one would expect. Surely this is

Aligning icon to the left in JTabbedPane in Nimbus Look and Feel

杀马特。学长 韩版系。学妹 提交于 2019-12-18 08:39:15
问题 I was creating an application with JTabbedPane using Nimbus look and feel I have used this code to place tabs: pane.addTab("Welcome",new ImageIcon("resources\\1.png"),mainPanel,"Takes to the welcome page"); I want the icon to appear on the left and 回答1: You can set a custom component for rendering the tab title, through JTabbedPane.setTabComponentAt(int index, Component component) method: Sets the component that is responsible for rendering the title for the specified tab . A null value means

“Highlighting” specific rows in a JTable

柔情痞子 提交于 2019-12-18 07:23:23
问题 I would like to highlight specific rows in a JTable whenever the contents of the a cell match with an input from the user. The following code is what I have that works thus far: JTable table = new JTable(model) { public Component prepareRenderer( TableCellRenderer renderer, int row, int column) { Component c = super.prepareRenderer(renderer, row, column); if (!isRowSelected(row) ) { c.setBackground((hashMapcontainer .containsKey(row)) ? Color.GREEN : getBackground()); } return c; } @Override

Controlling Color in Java Tabbed Pane

偶尔善良 提交于 2019-12-18 04:16:24
问题 I have been going nuts trying to figure this out. I am trying to elimenate a light blue background that appears in a JTabbedPane. I've tried everything and nothing seems to work. Below is my code. If you run it, it will show the tab, when selected with a light blue background and a thing blue border at the top. I want to control this color. But how? import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.plaf.ColorUIResource; public

JTabbedPane - set default border around tabs..?

蓝咒 提交于 2019-12-17 16:52:51
问题 I am using a JTabbedPane in my application. I have added two tabs which are instances of a custom class "ContentPanel". This extends JPanel and sets the background, border etc etc. Basically it means I dont have to set the properties of each JPanel I want to apply this colour scheme to. I notice that not only does their border appear but another border (which, I think, is blue - at least on my screen) appears around this border, connected to the tab "selectors" themselves (i.e. the buttons

How to change background color of JTabbedPane?

主宰稳场 提交于 2019-12-17 04:35:12
问题 I know you can modify the LaF properties, but how do you accomplish this without doing such? I only ask because setBackground doesn't seem to do it. Note that I'm looking to change the following properties: TabbedPane.background (or TabbedPane.contentAreaColor ?) TabbedPane.tabAreaBackground 回答1: Using TabComponentsDemo as an example, setBackgroundAt() seems to work: private void initTabComponent(int i) { pane.setTabComponentAt(i, new ButtonTabComponent(pane)); pane.setBackgroundAt(i, Color