By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,230 Members | 2,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,230 IT Pros & Developers. It's quick & easy.

Swing tab conponent can be multiline.Please see class swingtab.

P: 2
I want to use SWT tab compnent and make it be multiline,but I fail.please

see the class TabFolderExample.
Can aneone help me?

Expand|Select|Wrap|Line Numbers
  1.  import java.awt.BorderLayout; 
  2. import java.awt.event.WindowAdapter;
  3. import java.awt.event.WindowEvent;
  4.  
  5. import javax.swing.JDialog;
  6. import javax.swing.JLabel;
  7. import javax.swing.JPanel;
  8. import javax.swing.JTabbedPane;
  9.  
  10.  
  11. public class swingtab extends JDialog {
  12.  
  13.     /**
  14.      * Launch the application
  15.      * @param args
  16.      */
  17.     public static void main(String args[]) {
  18.         try {
  19.             swingtab dialog = new swingtab();
  20.             dialog.addWindowListener(new WindowAdapter() {
  21.                 public void windowClosing(WindowEvent e) {
  22.                     System.exit(0);
  23.                 }
  24.             });
  25.             dialog.setVisible(true);
  26.         } catch (Exception e) {
  27.             e.printStackTrace();
  28.         }
  29.     }
  30.  
  31.     /**
  32.      * Create the dialog
  33.      */
  34.     public swingtab() {
  35.         super();
  36.         getContentPane().setLayout(null);
  37.         this.setBounds(20, 10, 400, 325);
  38.  
  39.         final JTabbedPane tabPane = new JTabbedPane();
  40.  
  41. JPanel basicPanel = new JPanel();
  42. basicPanel.setLayout(null);
  43. basicPanel.setBounds(10, 10, tabPane.getWidth() - 30, 
  44.  
  45. tabPane.getHeight());
  46.  
  47. JLabel lbl1 = new JLabel("this is tab 1");
  48. lbl1.setBounds(5, 5, 100, 25);
  49. basicPanel.add(lbl1);
  50.  
  51. tabPane.addTab("Basics", basicPanel);
  52.  
  53. JPanel advancedPanel = new JPanel();
  54. advancedPanel.setLayout(null);
  55. advancedPanel.setBounds(tabPane.getX(), tabPane.getY(), 
  56.  
  57. tabPane.getWidth() - 30, tabPane.getHeight());
  58.  
  59. JLabel lbl2 = new JLabel("this is tab 2");
  60. lbl2.setBounds(5, 5, 100, 25);
  61. advancedPanel.add(lbl2);
  62.  
  63. tabPane.addTab("Advanced ", advancedPanel);
  64.  
  65. JPanel panel = new JPanel();
  66. panel.setLayout(null);
  67.  
  68. JLabel lbl3 = new JLabel("this is tab 3");
  69. lbl3.setBounds(5, 5, 100, 25);
  70. panel.add(lbl3);
  71.  
  72. tabPane.addTab("New Instance ", panel);
  73.  
  74. // JPanel panel1 = new JPanel();
  75. // panel.setLayout(null);
  76. // tabPane.addTab("Playback ", panel1);
  77. // 
  78. // JPanel panel2 = new JPanel();
  79. // panel.setLayout(null);
  80. // tabPane.addTab("Green Info Display ", panel2);
  81.  
  82. tabPane.setBounds(10, 35, 130, 250);
  83.         this.add(tabPane);
  84.         //
  85.     }
  86. }
  87.  
  88. import org.eclipse.swt.SWT;
  89. import org.eclipse.swt.layout.FillLayout;
  90. import org.eclipse.swt.layout.GridData;
  91. import org.eclipse.swt.layout.GridLayout;
  92. import org.eclipse.swt.widgets.Button;
  93. import org.eclipse.swt.widgets.Composite;
  94. import org.eclipse.swt.widgets.Display;
  95. import org.eclipse.swt.widgets.Label;
  96. import org.eclipse.swt.widgets.Shell;
  97. import org.eclipse.swt.widgets.TabFolder;
  98. import org.eclipse.swt.widgets.TabItem;
  99. import org.eclipse.swt.widgets.Text;
  100.  
  101. public class TabFolderExample {
  102.  
  103. public static void main(String[] args) {
  104. Shell shell = new Shell(Display.getCurrent(), SWT.SHELL_TRIM);
  105. shell.setLayout(new FillLayout());
  106. TabFolder tabFolder = new TabFolder(shell, SWT.TOP);
  107.  
  108. for (int tab = 0; tab < 9; tab++) {
  109.  
  110. TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
  111. tabItem.setText("Tab" + (tab + 1));
  112. Composite composite = new Composite(tabFolder, SWT.NONE);
  113. composite.setLayout(new GridLayout(2, false));
  114. tabItem.setControl(composite);
  115.  
  116. for (int item = 0; item < 10; item++) {
  117. Label label = new Label(composite, SWT.LEFT);
  118. label.setFocus();
  119. label.setText("Label &" + (item + 1));
  120. label.setLayoutData(new GridData());
  121. Text text1 = new Text(composite, SWT.LEFT | SWT.BORDER);
  122. text1.setText("Text " + (item + 1));
  123. GridData textData = new GridData();
  124. textData.grabExcessHorizontalSpace = true;
  125. textData.widthHint = 200;
  126. text1.setLayoutData(textData);
  127. }
  128. }
  129.  
  130. Display display = Display.getCurrent();
  131. shell.pack();
  132. shell.setVisible(true);
  133. shell.setFocus();
  134. while (!shell.isDisposed()) {
  135. if (!display.readAndDispatch()) {
  136. display.sleep();
  137. }
  138. }
  139. display.dispose();
  140. }
  141. }
  142.  
Jun 6 '07 #1
Share this Question
Share on Google+
1 Reply


blazedaces
100+
P: 284
What is the problem? What errors are you getting? What shows up when you compile/run this?

Put your code in code brackets please (look at the "Reply Guidelines" box that appears when you're replying on the right side of the screen).

-blazed
Jun 6 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.