473,763 Members | 9,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Swing tab conponent can be multiline.Pleas e see class swingtab.

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

see the class TabFolderExampl e.
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 3175
blazedaces
284 Contributor
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
3460
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 line spacing is very close (for example, when I use HTML in JLabels, or even in JTextAreas), but on the other Linux box, the line spacing is much wider. I'm using default Swing fonts -- I'm not setting anything. I can't find a field or function...
1
9651
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 and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
1
1371
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
1721
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 sent to me: A one Gig Jump drive
3
12539
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 couldn't manage my swing in proper layout pls run and check Code:
1
1120
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. http://www.code2000.net/keybkann.htm I need to produce something like this, using java Swing... Can anyone please advice?
6
1264
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 tab_model = new DefaultModel(...); JTable tab = new JTable(tab_model); //Now if I change to tab_model then automatically updation notification goes to tab??
6
51167
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 help people display some nice widgets quickly without explaining some issues that need to be tackled when a full application needs to be developed. This article does not go into full implementation details because those can be found by reading the...
0
1343
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 public class test2 extends javax.swing.JFrame { /** Creates new form test2 */ public test2() {
1
9938
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.