Login Register






Tabbed pane in java filter_list
Author
Message
Tabbed pane in java #1
Hi!!!!!
I'm currently working on simple java project. I've to customize my code for attractive appearence of tabbed pane. My code and output like this...
[Image: ykX36UM.png]
source code of tabbed pane:
Code:
package gui; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JTabbedPane; /** * * @author SagunThapaMagar */ public class TestTab extends JFrame { JTabbedPane jtab = new JTabbedPane(); Tab_panel tabpane[] = new Tab_panel[2]; public TestTab() { setSize(600, 400); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); add(jtab); tabpane[0] = new Tab_panel(); jtab.addTab("New-1",new ImageIcon(getClass().getResource("/images/newfolder.png")), tabpane[0]); jtab.addTab("New-2",new ImageIcon(getClass().getResource("/images/newfolder.png")), tabpane[1]); } public static void main(String nugas[]) { TestTab tb = new TestTab(); } }
code of tab_panel:
Code:
public class Tab_panel extends JPanel{ private final JPanel txtArea=new JPanel(); public Tab_panel(){ setLayout(new BorderLayout()); add(txtArea, BorderLayout.CENTER); } }
I want my tabbed pane like this:
[Image: cEqOOM2.png]
Thank you.:troll:


RE: Tabbed pane in java #2
I think you're using the Nimbus or metal look and feel. Change it to system look and feel. Since you're using windows and so you have tabs like windows have. If you run this on Linux the tabs will look different.

On windows you will get that look and feel.

[Image: fGd7UIW.png]

To set the Cross platform look and feel use this :-

[
Code:
java]UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());


here the code :-

TabbedPaneTest.java

[
Code:
java] package testtab; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; /** * @author Psycho_Coder * */ public class TabbedPaneTest extends JFrame { private static final long serialVersionUID = 1L; public TabbedPaneTest() { setContentPane(new TabbedPaneTestPanel()); setSize(new Dimension(500, 400)); setResizable(false); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (UnsupportedLookAndFeelException e) { e.printStackTrace(); } SwingUtilities.invokeLater(new Runnable() { public void run() { new TabbedPaneTest().setVisible(true); } }); } }


TabbedPaneTestPanel.java

[
Code:
java] /** * */ package testtab; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.JPanel; import javax.swing.JTabbedPane; /** * @author Psycho_Coder * */ public class TabbedPaneTestPanel extends JPanel { private static final long serialVersionUID = 1L; private JTabbedPane tabpane = null; public TabbedPaneTestPanel() { setPreferredSize(new Dimension(500, 400)); setLayout(new BorderLayout()); tabpane = new JTabbedPane(); tabpane.setPreferredSize(new Dimension(400, 400)); tabpane.addTab("Test Tab1", null); tabpane.addTab("Test Tab2", null); tabpane.addTab("Test Tab3", null); add(tabpane, BorderLayout.CENTER); } }


If you want to have a tab with close button then see this http://www.codeproject.com/Articles/1849...osing-Tabs
[Image: OilyCostlyEwe.gif]


RE: Tabbed pane in java #3
Thanks........

LookAndFeel working well and now appears like this
[Image: YrWzCco.png]
But while using ClosableTabbedPane, it's not working well.............
:Sealed:
[Image: OfbSenT.png]
From which class subclass ClosableTabbedPane is extended?
:troll:


RE: Tabbed pane in java #4
ClosableTabbedPane is not part of the standard library. You have do download the project and include it to your classpath in order to use the implementation.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]