473,748 Members | 6,161 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 3171
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
9649
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
1369
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
12538
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
1263
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
51162
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
1342
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() {
0
8828
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9243
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
8241
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
6795
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
6073
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();...
2
2780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2213
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.