Monday 15 June 2015

java - Dynamic JComboBox Size -


I have JComboBox that has long been in string s I only need to see their full length during selection, therefore, I want to be JComboBox full size and otherwise small.

The following code works, but since I am very java, I am thinking that there is a better or more standard way of doing this.

Thank you.

  import java .awt *. Import javax.swing *; Import javax.swing.event. *; Public Category DynamicJComboBox {Create Private Static Zero and Create ShowuI () {// and set up Window JFrame Frame = New JFram (); Frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Frame.setLayout (New Flow Layout ()); Frame.setSize (250, 100); JComboBox box = new JComboBox (); Box.addItem ("Actually Long Line Number One"); Box.addItem ("Actually Long Line Number Two"); Box.addItem ("Actually Long Line Number Three"); Box.addItem ("Actually Long Line Number Four"); Box.setPreferredSize (new dimension (100, 30)); Box.addPopupMenuListener (New PopupManuListener) {@Override public void popupMenuCanceled (PopupMenuEvent e) {} Override public blank popupManualWebback Exploreable (popup menuewit E) {box.setSize (100,30); @ Override public empty popupManualWebbackWebBox (PopupMenuEventE) {Box.setSize (200,30);}}); Frame.add (box); Frame.setVisible (true); } Public static zero main (string [] args) {try} {UIManager.setLookAndFeel ("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } (Exception Ex) {} SwingUtilities.invokeLater ((- -> gt; createAndShowGUI ();}); }}  

The following code seems to work

Not really because you change the size of the combo box which will overwrite the combo box on any of its component display on its right side. In addition, the combo box is drawn in the middle of the Arrow combo box.

Check out. This solution also uses popupmenulist (so you were on the right track), but it only increases the width of the popup when not displayed, even the combo box is displayed.


No comments:

Post a Comment