Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Eclipse Collections Categorically: Level up your programming game
this week in the
Open Source Projects
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Swing / AWT / SWT
JComboBox in panel
Nicky Eng
Ranch Hand
Posts: 378
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i have comboBox in my panel.
and i want it to be display as normal as below:
but, after i run it, i got this :
the box of scrolling down is missing, still it can scroll down to select item.
I just want the box appear in normal display.
my code is fine rite?
here is it is:
JComboBox cb= new JComboBox(); cd.addItem("1"); cd.addItem("2"); cd.addItem("3"); add(cd); cd.setBounds(100,100,65, 22); cd.setOpaque(true);
so where is it wrong?
From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Michael Dunn
Ranch Hand
Posts: 4632
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
works OK for me.
post a working sample program, which displays the problem.
Nicky Eng
Ranch Hand
Posts: 378
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
here is the sample after i run it:
i separate the panel and frame as different class.
here is my panel class:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class CustBookPanel extends javax.swing.JPanel { public CustBookPanel() { initComponents(); } private void initComponents() { titleLabel = new javax.swing.JLabel(); sp1 = new javax.swing.JSeparator(); fnLabel = new javax.swing.JLabel(); lnLabel = new javax.swing.JLabel(); contactLabel = new javax.swing.JLabel(); add1Label = new javax.swing.JLabel(); add2Label = new javax.swing.JLabel(); emailLabel = new javax.swing.JLabel(); firstNameTf = new javax.swing.JTextField(); lastNameTf = new javax.swing.JTextField(); contactTf = new javax.swing.JTextField(); add2Tf = new javax.swing.JTextField(); addTf = new javax.swing.JTextField(); emailTf = new javax.swing.JTextField(); srLabel = new javax.swing.JLabel(); seatBox = new javax.swing.JComboBox(); totalLabel = new javax.swing.JLabel(); totalDisplay = new javax.swing.JTextField(); sp2 = new javax.swing.JSeparator(); setLayout(null); setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); titleLabel.setFont(new java.awt.Font("Arial", 0, 18)); titleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); titleLabel.setText("Customer Seat Reversation"); titleLabel.setOpaque(true); add(titleLabel); titleLabel.setBounds(190, 10, 260, 30); add(sp1); sp1.setBounds(40, 60, 590, 20); fnLabel.setText("First Name : "); add(fnLabel); fnLabel.setBounds(50, 80, 80, 20); lnLabel.setText("Last Name :"); add(lnLabel); lnLabel.setBounds(50, 120, 80, 20); contactLabel.setText("Contact Number :"); add(contactLabel); contactLabel.setBounds(50, 160, 100, 20); add1Label.setText("Address 1 :"); add(add1Label); add1Label.setBounds(50, 200, 90, 20); add2Label.setText("Address 2 :"); add(add2Label); add2Label.setBounds(50, 240, 90, 20); emailLabel.setText("Email Address :"); add(emailLabel); emailLabel.setBounds(50, 280, 100, 20); add(firstNameTf); firstNameTf.setBounds(160, 80, 150, 22); add(lastNameTf); lastNameTf.setBounds(160, 120, 150, 22); contactTf.setFont(new java.awt.Font("Tahoma", 0, 12)); add(contactTf); contactTf.setBounds(160, 160, 100, 22); add(add2Tf); add2Tf.setBounds(160, 240, 290, 22); add(addTf); addTf.setBounds(160, 200, 290, 22); add(emailTf); emailTf.setBounds(160, 280, 270, 22); srLabel.setText("Seat Reserved : "); add(srLabel); srLabel.setBounds(390, 80, 100, 20); seatBox.addItem("1"); seatBox.addItem("2"); seatBox.addItem("3"); seatBox.addItem("4"); seatBox.addItem("5"); seatBox.addItem("6"); seatBox.addItem("7"); seatBox.addItem("8"); seatBox.addItem("9"); seatBox.addItem("10"); add(seatBox); seatBox.setBounds(490, 80, 50, 22); seatBox.setOpaque(true); seatBox.setSelectedIndex(0); totalLabel.setText("Total ($) :"); add(totalLabel); totalLabel.setBounds(390, 120, 90, 20); add(totalDisplay); totalDisplay.setBounds(490, 120, 70, 22); add(sp2); sp2.setBounds(40, 340, 590, 20); }// </editor-fold> // Variables declaration - do not modify private javax.swing.JLabel add1Label; private javax.swing.JLabel add2Label; private javax.swing.JTextField add2Tf; private javax.swing.JTextField addTf; private javax.swing.JLabel contactLabel; private javax.swing.JTextField contactTf; private javax.swing.JLabel emailLabel; private javax.swing.JTextField emailTf; private javax.swing.JTextField firstNameTf; private javax.swing.JLabel fnLabel; private javax.swing.JTextField lastNameTf; private javax.swing.JLabel lnLabel; private javax.swing.JComboBox seatBox; private javax.swing.JSeparator sp1; private javax.swing.JSeparator sp2; private javax.swing.JLabel srLabel; private javax.swing.JLabel titleLabel; private javax.swing.JTextField totalDisplay; private javax.swing.JLabel totalLabel; // End of variables declaration }
From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Nicky Eng
Ranch Hand
Posts: 378
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
i got this in my frame class:
plaf= "javax.swing.plaf.metal.MetalLookAndFeel"; try{ UIManager.setLookAndFeel(plaf); SwingUtilities.updateComponentTreeUI(connectDialog.this); } catch(Exception e){ e.printStackTrace(); }
when i change it to "com.sun.java.swing.plaf.motif.MotifLookAndFeel", it works on that.
how come metallookandfeel not displaying well?
From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Michael Dunn
Ranch Hand
Posts: 4632
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
shows up normally on my PC
winxp pro sp2,
java
1.5.0_05
if you are using a different os, search sun's bug database, keywords
[os name] JComboBox Arrow ArrowButton
Nicky Eng
Ranch Hand
Posts: 378
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
winxp home sp2, java 1.5.0_05
From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Michael Dunn
Ranch Hand
Posts: 4632
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
"javax.swing.plaf.metal.MetalLookAndFeel"
also works OK (default for 1.5??)
Michael Dunn
Ranch Hand
Posts: 4632
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
weird, the only diff is home vs pro, which, to me, shouldn't make a difference
here's your code stripped down to just the combobox and separators, which
runs OK on my pc
run on yours, see if it still shows incorrectly
import java.awt.*; import java.awt.event.*; import javax.swing.*; class CustBookPanel extends javax.swing.JPanel { public CustBookPanel() { setPreferredSize(new Dimension(700,400));//<---added this initComponents(); } private void initComponents() { sp1 = new javax.swing.JSeparator(); seatBox = new javax.swing.JComboBox(); sp2 = new javax.swing.JSeparator(); setLayout(null); add(sp1); sp1.setBounds(40, 60, 590, 20); seatBox.addItem("1"); seatBox.addItem("2"); seatBox.addItem("3"); add(seatBox); seatBox.setBounds(490, 80, 50, 22); add(sp2); sp2.setBounds(40, 340, 590, 20); } private javax.swing.JComboBox seatBox; private javax.swing.JSeparator sp1; private javax.swing.JSeparator sp2; } class Testing extends JFrame { public Testing() { try{ UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); SwingUtilities.updateComponentTreeUI(Testing.this); } catch(Exception e){ e.printStackTrace(); } add(new CustBookPanel()); setDefaultCloseOperation(EXIT_ON_CLOSE); pack(); setVisible(true); } public static void main(String[] args){new Testing();} }
Nicky Eng
Ranch Hand
Posts: 378
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
your code runs ok.
so something wrong with my separator?
From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Michael Dunn
Ranch Hand
Posts: 4632
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
the separators are OK - I left them in only for 'dressing'
must be something else in your code, something you haven't posted.
as mentioned earlier, post something that we can copy/paste/compile/run and
see the problem.
unfortunately I'm off to work now, so I won't be able to check back for a while.
someone else might be able to isolate the problem.
Nicky Eng
Ranch Hand
Posts: 378
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
ok. thanks for your posts.
now i will included all my coding needed :
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class theatre extends javax.swing.JFrame implements ActionListener{ public theatre() { initComponents(); } private void initComponents() { timeLabel=new JLabel(); sysLabel = new javax.swing.JLabel(); btnCon = new JButton(); btnConfirm = new JButton(); menuBar = new javax.swing.JMenuBar(); fileMenu = new javax.swing.JMenu(); connectM = new javax.swing.JMenuItem(); exitM = new javax.swing.JMenuItem(); optionMenu = new JMenu(); custM= new JMenuItem(); custMenu = new JMenu(); oneCustM = new JMenuItem(); otherMenu = new JMenu(); aboutM = new JMenuItem(); plaf= "javax.swing.plaf.metal.MetalLookAndFeel"; try{ UIManager.setLookAndFeel(plaf); SwingUtilities.updateComponentTreeUI(theatre.this); } catch(Exception e){ e.printStackTrace(); } getContentPane().setLayout(null); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("eBook Entry"); setResizable(false); sysLabel.setFont(new java.awt.Font("Century Gothic", 1, 36)); sysLabel.setForeground(java.awt.Color.magenta); sysLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); sysLabel.setText("eBook Theatre System"); sysLabel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); getContentPane().add(sysLabel); sysLabel.setBounds(300, 10, 430, 60); btnCon.setFont(new java.awt.Font("Tahoma", 1, 12)); btnCon.setText("Next"); getContentPane().add(btnCon); btnCon.setBounds(600, 620, 100, 30); btnCon.addActionListener(this); btnConfirm.setFont(new java.awt.Font("Tahoma", 1, 12)); btnConfirm.setText("Confirm"); getContentPane().add(btnConfirm); btnConfirm.setBounds(600, 620, 100, 30); btnConfirm.addActionListener(this); //file menu set up and have 2 item inside : Connect and Exit. fileMenu.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); fileMenu.setBorderPainted(true); fileMenu.setFont(new java.awt.Font("Arial", 0, 18)); fileMenu.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); fileMenu.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); fileMenu.setText("File"); fileMenu.setPreferredSize(new java.awt.Dimension(78, 27)); fileMenu.add(connectM); fileMenu.addSeparator(); fileMenu.add(exitM); connectM.setText("Sign In As..."); connectM.addActionListener(this); exitM.setText("Exit"); exitM.addActionListener(this); // set up Options menu and add Customer menuItem into it. optionMenu.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); optionMenu.setBorderPainted(true); optionMenu.setFont(new java.awt.Font("Arial", 0, 18)); optionMenu.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); optionMenu.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); optionMenu.setText("Options"); optionMenu.setPreferredSize(new java.awt.Dimension(85, 27)); custM.setText("All Customers Reservation"); custM.addActionListener(this); custMenu.setText("Search ... "); custMenu.add(oneCustM); oneCustM.setText("Search by One"); oneCustM.addActionListener(this); optionMenu.add(custM); optionMenu.addSeparator(); optionMenu.add(custMenu); // Set up the Other menu and other menu item. otherMenu.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); otherMenu.setBorderPainted(true); otherMenu.setFont(new java.awt.Font("Arial", 0, 18)); otherMenu.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); otherMenu.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); otherMenu.setText("Others"); otherMenu.setPreferredSize(new java.awt.Dimension(83,27)); otherMenu.add(aboutM); aboutM.setText("About..."); aboutM.addActionListener(this); // ---------------------------------------- menuBar.setMaximumSize(new java.awt.Dimension(0, 50)); menuBar.setPreferredSize(new java.awt.Dimension(0, 45)); menuBar.add(fileMenu); menuBar.add(optionMenu); menuBar.add(otherMenu); setJMenuBar(menuBar); pack(); setSize(1024,740); } public void addCustPanel() { cust_pane = new CustBookPanel(); getContentPane().add(cust_pane); cust_pane.setBounds(230,130,680,400); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==connectM) { } if(ae.getSource()==exitM) { System.exit(0); } if(ae.getSource()==custM) { } if(ae.getSource()==aboutM) { } if(ae.getSource()==oneCustM) { } if(ae.getSource()==btnCon) { } if(ae.getSource()==btnConfirm) { } } private JLabel timeLabel; private javax.swing.JLabel sysLabel; private javax.swing.JMenuBar menuBar; private javax.swing.JMenuItem connectM; private javax.swing.JMenuItem exitM; private javax.swing.JMenu fileMenu; private JMenu optionMenu; private JMenuItem custM; private JMenu custMenu; private JMenuItem oneCustM; private JMenu otherMenu; private JMenuItem aboutM; private JButton btnCon; private JButton btnConfirm; private CustBookPanel cust_pane; private String plaf; }
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class CustBookPanel extends javax.swing.JPanel { public CustBookPanel() { initComponents(); } private void initComponents() { titleLabel = new javax.swing.JLabel(); fnLabel = new javax.swing.JLabel(); lnLabel = new javax.swing.JLabel(); contactLabel = new javax.swing.JLabel(); add1Label = new javax.swing.JLabel(); add2Label = new javax.swing.JLabel(); emailLabel = new javax.swing.JLabel(); srLabel = new javax.swing.JLabel(); totalLabel = new javax.swing.JLabel(); firstNameTf = new javax.swing.JTextField(); lastNameTf = new javax.swing.JTextField(); contactTf = new javax.swing.JTextField(); add2Tf = new javax.swing.JTextField(); addTf = new javax.swing.JTextField(); emailTf = new javax.swing.JTextField(); totalDisplay = new javax.swing.JTextField(); seatBox = new javax.swing.JComboBox(); sp1 = new javax.swing.JSeparator(); sp2 = new javax.swing.JSeparator(); setLayout(null); setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); titleLabel.setFont(new java.awt.Font("Arial", 0, 18)); titleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); titleLabel.setText("Customer Seat Reversation"); titleLabel.setOpaque(true); add(titleLabel); titleLabel.setBounds(190, 10, 260, 30); add(sp1); sp1.setBounds(40, 60, 590, 15); fnLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); fnLabel.setText("First Name : "); add(fnLabel); fnLabel.setBounds(50, 80, 80, 20); lnLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); lnLabel.setText("Last Name :"); add(lnLabel); lnLabel.setBounds(50, 120, 80, 20); contactLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); contactLabel.setText("Contact Number :"); add(contactLabel); contactLabel.setBounds(50, 160, 100, 20); add1Label.setFont(new java.awt.Font("Tahoma", 0, 12)); add1Label.setText("Address 1 :"); add(add1Label); add1Label.setBounds(50, 200, 90, 20); add2Label.setFont(new java.awt.Font("Tahoma", 0, 12)); add2Label.setText("Address 2 :"); add(add2Label); add2Label.setBounds(50, 240, 90, 20); emailLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); emailLabel.setText("Email Address :"); add(emailLabel); emailLabel.setBounds(50, 280, 100, 20); firstNameTf.setFont(new java.awt.Font("Tahoma", 0, 12)); add(firstNameTf); firstNameTf.setBounds(160, 80, 150, 22); lastNameTf.setFont(new java.awt.Font("Tahoma", 0, 12)); add(lastNameTf); lastNameTf.setBounds(160, 120, 150, 22); contactTf.setFont(new java.awt.Font("Tahoma", 0, 12)); add(contactTf); contactTf.setBounds(160, 160, 100, 22); add2Tf.setFont(new java.awt.Font("Tahoma", 0, 12)); add(add2Tf); add2Tf.setBounds(160, 240, 290, 22); addTf.setFont(new java.awt.Font("Tahoma", 0, 12)); add(addTf); addTf.setBounds(160, 200, 290, 22); emailTf.setFont(new java.awt.Font("Tahoma", 0, 12)); add(emailTf); emailTf.setBounds(160, 280, 270, 22); srLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); srLabel.setText("Seat Reserved : "); add(srLabel); srLabel.setBounds(390, 80, 100, 20); seatBox.setFont(new java.awt.Font("Tahoma", 0, 12)); seatBox.addItem("1"); seatBox.addItem("2"); seatBox.addItem("3"); seatBox.addItem("4"); seatBox.addItem("5"); seatBox.addItem("6"); seatBox.addItem("7"); seatBox.addItem("8"); seatBox.addItem("9"); seatBox.addItem("10"); add(seatBox); seatBox.setBounds(495, 80, 50, 22); seatBox.setOpaque(true); seatBox.setSelectedIndex(0); totalLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); totalLabel.setText("Total ($) :"); add(totalLabel); totalLabel.setBounds(390, 120, 90, 20); totalDisplay.setFont(new java.awt.Font("Tahoma", 0, 12)); add(totalDisplay); totalDisplay.setBounds(490, 120, 70, 22); add(sp2); sp2.setBounds(40, 340, 590, 20); } private javax.swing.JLabel add1Label; private javax.swing.JLabel add2Label; private javax.swing.JTextField add2Tf; private javax.swing.JTextField addTf; private javax.swing.JLabel contactLabel; private javax.swing.JTextField contactTf; private javax.swing.JLabel emailLabel; private javax.swing.JTextField emailTf; private javax.swing.JTextField firstNameTf; private javax.swing.JLabel fnLabel; private javax.swing.JTextField lastNameTf; private javax.swing.JLabel lnLabel; private javax.swing.JComboBox seatBox; private javax.swing.JSeparator sp1; private javax.swing.JSeparator sp2; private javax.swing.JLabel srLabel; private javax.swing.JLabel titleLabel; private javax.swing.JTextField totalDisplay; private javax.swing.JLabel totalLabel; }
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class eBook { private static theatre th; public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { th = new theatre(); th.setVisible(true); th.addCustPanel(); } }); } }
[ October 16, 2006: Message edited by: Nicky Eng ]
[ October 16, 2006: Message edited by: Nicky Eng ]
From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Michael Dunn
Ranch Hand
Posts: 4632
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
swap these
th.setVisible(true);
th.addCustPanel();
to
th.addCustPanel();
th.setVisible(true);
Nicky Eng
Ranch Hand
Posts: 378
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
works now.
REALLY thank you for spending time on my problem.
thanks
alot
.
From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
And then the flying monkeys attacked. My only defense was this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
question regarding j query grid
Question from NickyEng
Passing session between two web application
Funny gassy cartoons!
JTable width and height
More...