jtabbedpane

Java - how do I gain focus on JTextArea when selecting a new JTabbedPane

荒凉一梦 提交于 2019-12-24 01:49:07
问题 I have a swing GUI with multiple JTabbedPane s; each tab contains two JButtons at the top, then a JTextArea (for user input), and a JTextField at the bottom for a result. My problem is that I can't get the JTextArea to gain focus after switching tabs without either clicking in it with the mouse or using the tab key on the keyboard? I have... frame.addWindowFocusListener(new WindowAdapter() { public void windowGainedFocus(WindowEvent e) { textArea_1.requestFocusInWindow(); ...and this works

Add a JLabel in the JTabbedPane header

纵饮孤独 提交于 2019-12-24 00:42:11
问题 I have this JDialog with a JTabbedPane: I just want to add a JLabel in the right-top area of the JTabbedPane so i can fire some events (e.g close the JDialog). And i don't want to make it a JFrame. PS: I know that is may be duplicated, but none of the responses give me a solution. 回答1: Well, actually that positioning inside JTabbedPane is not supported in Swing. But you can always make some street magic with layouts and layers: public static void main ( String[] args ) { try { UIManager

How to check whether the tab is active or not in JTabbedPane?

☆樱花仙子☆ 提交于 2019-12-23 08:18:09
问题 How can I check whether a tab in a JTabbedPane instance is active or not, in the class of the tab (nested class) itself and not in the enclosing class? I know that there is a method booloean isEnabledAt(int index); but this method can only be called in the enclosing class. Whereas I want to check whether the tab is currently selected within the tab class itself (nested class). Can anybody please suggest how? 回答1: Your component has a parent, eventually the JTabbedPane . JTabbedPane has

Get JTable from selected tab at JTabbedPane

被刻印的时光 ゝ 提交于 2019-12-22 11:08:11
问题 I have JTabbedPane with many generated dynamically JPanels, that contains JTable. How can i get/set JTable from the selected JTabbedPane tab? Already tried to use JTabbedPane.getComponents(), but it doesn't contain any JTable components. 回答1: myPane.getSelectedComponent().getComponents(); will give you all components of the selected tab's component. You can search with a loop for the class JTable, if there is more than 1 component in your JPanel. 来源: https://stackoverflow.com/questions

JTabbedPane: Actions performed before displaying selected tab

五迷三道 提交于 2019-12-22 07:09:01
问题 When one of the panels present in a JTabbedPane is clicked, I need to perform a few actions at the start. Say, for example, I need to check the username and password. Only if those match, the particular panel operations need to be performed. Can you suggest any methods? 回答1: Not sure I fully understand your question, but I would do something like: Add a ChangeListener to the JTabbedPane to listen for the first tab click. When a ChangeEvent occurs perform the login on a background thread using

JTabbedPane tab component resize to fit

人走茶凉 提交于 2019-12-21 22:04:08
问题 I want to make my tab labels share the JTabbedPane width. If there's one tab, fit whole width, if two tabs, share width, if three, 1/3 for each and so on... i don't even know if it's possible to do it without putting a component there and resizing it, maybe JTabbedPane has a way of resizing it's tab label via method and i don't know... Anyone got any idea how to make it by the easiest way possible? 回答1: As @trashgod already noted, the tab layout is handled by the LAF-specific

Get the in-focus tab after closing a tab

隐身守侯 提交于 2019-12-20 07:39:48
问题 In a JTabbedPane, I associated a custom-made Data object to each added tab. I also have a corresponding Metadata object that shows up in another panel when the tab is selected. The problem I have now is when a tab is closed, the metadata panel shows the metadata of the Data object in the tab that just gets closed. Ideally, I want the panel to show the metadata for the in-focus tab that the user sees. However, the act of closing a tab means the “selected tab” is the tab being closed, so

How to change background color of JTabbedPane in runtime?

廉价感情. 提交于 2019-12-20 04:15:57
问题 I have founds loads of examples that change the background color of JTabbedPane using either setBackgroundAt() and UIManager.put("JTabbedPane...") However, I want to create an onclick event on a checkbox that changes the background color to green when you select it, and back to default when you unselect it. I haven't been able to make that work using the above methods. Any ideas? PS: I can change the foreground color by using setForgroundAt() but not the background for some reason 回答1: LAFs

MouseEvents for a JTabbedPane Tab component are not bleeding through

こ雲淡風輕ζ 提交于 2019-12-20 02:46:08
问题 I have a JTabbedPane with a custom tab component. That component contains a JLabel (To display the tab title) and a JButton (A close button). When I change the text in the JLabel the JLabel stops receiving mouse events and I can no longer select that tab when I click directly on the label instead if I click around the label then I can select the tab. Any ideas? A snippet of the code: class ShellPanelTabComponent extends JPanel implements ActionListener{ private ShellPanel panel; private

How to check if a jframe is opened?

柔情痞子 提交于 2019-12-20 02:35:29
问题 My code below create a new array and sends it to chat(jFrame). String info1[]=new String[3]; // username , userid , userid2 are variables info1[0]=username4; info1[1]=""+userid; info1[2]=""+userid2; chat.main(info1); But i need to modify this code to work such a way that it , if the chat jframe was opened, then dont open a new jFrame .But instead open a new tab in chat jframe . The code for chat frame is : private void formWindowActivated(java.awt.event.WindowEvent evt) { JScrollPane panel2 =