473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

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
1 3126
blazedaces
284 100+
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

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

Similar topics

0
by: Hal Vaughan | last post by:
I'm testing a GUI app on a couple Linux boxen and one Win2k box. I'm using Java 1.4.2 on each (or the closest on Win2k -- whatever version comes close). On one Linux box and the Win2k box the...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
1
by: freegnu | last post by:
hi all, i want to modify a class's interface, that will reference many classes which inherit it is there any advice to me? thanks
2
by: jhhbr549 | last post by:
I need my result to print out only in the box created with a scroll bar. It has to look like this. The Twelve Days of It by John H. Howard On the First day of It My true LOVE of Computers...
3
by: Nuwang | last post by:
Hai, I'm using a swing to connect database with swing application... 1. How this swing connect with access database... 2. Important thing is how change Button size and Font size Still I...
1
by: javateam | last post by:
Hi all, I have a situation where I need to be able to display foreign characters (asian languages) in a text area in my program. I have no idea on how to do this. ...
6
dmjpro
by: dmjpro | last post by:
Now a days I am working in Swing. So guys please help me to do my project. Actually the time is short to read out those things. What i have a confusion ..that ..... DefaultTableModel...
6
by: r035198x | last post by:
I have put together this article to give people starting Swing an awareness of issues that need to be considered when creating a Swing application. Most of the Swing tutorials that I have seen just...
0
by: phpuser123 | last post by:
I have a class test2 containing a button.When I press this button, I want to instantiate an object from Test3 and display the image in a panel on the newly created object.. test2 class ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.