Size of ComboBox

Hi All
I am placing my components in gridbag layout.
When I place a combobox and say that it occupies 3 cell in x direction
it only shows the size of the combobox to be equal to the maximum size
of element contained in it. How can i make it fill all the 3 cells.
Thanks
bib

Try putting wgtx of first component as 3 and the second component as 1.
Or try changing the gridthwidth of the first component.

Similar Messages

  • Size of combobox in JTable with custom cell editor

    Hi All -
    I have a JTable that displays a combobox in certain cells. I have a custom table model, renderer, and editor. All of that works fine. I render the combobox with the renderer, and then return the combobox as an editor in the editor so that it can drop down and actually be of use. My problem is - I set the size of the combobox with a setBounds call in the renderer, I add it to a panel, and return the panel - because I dont want the combobox to take up the entire space of the cell. This approach fails in the editor. The setBounds and setSize calls have no effect. As soon as you click the combobox, the editor takes over and all of a sudden the combobox resizes to the entire area of the cell. I assume this is because in the editor you arent actually placing anything - your simply returning the "editing form" of the component.
    So - anybody know of a way to work around this? Worst case, I could just allow the combobox to use the entire area of the cell - but it makes it uglier so I figured I would run it by the forums.
    Eric

    Rather than just redirect you to my previous answer from ages ago, I'll just give it again. :-)
    You can actually do this, but you have to get tricky. By default, the dropdown's width will be the same width as the cell... but it doesn't have to be that way. Essentially what you have to do is override the UI (MetalComboBoxUI) for the combo component. In your new customized UI component subclass (that you set the combo to use), modify the the createPopup() method of this UI class, and add your own logic to set the size of the popup before you return it.
    Ideally the size would be based on the computed max width of a rendered item shown in the combo, but really you could set it to whatever just to see how it works.

  • Set Maximum size for combobox editor in JTable

    Hi guys.
    I have a JTable with a custom JTextArea as editor for string datatypes.
    On the other hand, I have a combo editor too for some other columns of the table.
    My question is to know whether I can force the combox editor not to grow along with the text area.
    When I have a multiline text in a cell, I don 't want the combo box editor to fill the entire height of the row (the row height is continuously adjusted as user enter text into the text area cell editor), but to remain as big as just to render one line.
    Thanks.

    you know there's a swing forum, why not use it :-)
    As to your problem: the basicUI simply forces all editors to fit the cell size, returning more reasonable max-sizes for the combo wouldn't help. Way out might be to wrap into a panel with an appropriate layoutManager. Not entirely trivial, would expect some work ...
    Cheers
    Jeanette

  • Want to change the default size of compobox

    Hi,
    I want to change the default size of combobox in BorderLayout.How to change or it's possible to change?

    I have tried.But it doesn' effect.Please advice me.private javax.swing.JPanel getJPanel43() {
         if (ivjJPanel43 == null) {
              try {
                                    ivjJPanel43 = new javax.swing.JPanel();
                                    ivjJPanel43.setName("JPanel4");
              ivjJPanel43.setBorder(new javax.swing.border.EtchedBorder());
              ivjJPanel43.setLayout(new java.awt.BorderLayout());
              ivjJPanel43.setBackground(new java.awt.Color(220,222,248));
              ivjJPanel43.setBounds(796, 24,260, 295);
                                    ivjJPanel4t = new javax.swing.JPanel( new BorderLayout());
              ivjJPanel4t.setBackground(new java.awt.Color(220,222,248));
              ivjJLabel13t = new JLabel("Enter Firm", JLabel.CENTER);
              ivjJPanel4t.add( ivjJLabel13t, BorderLayout.NORTH );
              ivjJPanel5t = new javax.swing.JPanel();
                                    ivjJPanel5t.setLayout(null);
                                     getJComboBox30().setBounds(new Rectangle(100,100,150,200));
                                     ivjJPanel5t.add( getJComboBox30());
                                     ivjJPanel5t.setLayout(new BorderLayout());
    ivjJPanel5t.setBackground(new java.awt.Color(220,222,248));
                                            ivjJLabel14t = new JLabel("Firm ");
                                            ivjJPanel5t.add( ivjJLabel14t, BorderLayout.WEST );
                                            // ivjJTextField17t = new javax.swing.JTextField();
                                            ivjJPanel5t.add(getJComboBox30(), BorderLayout.CENTER);
                                            ivjJPanel4t.add(ivjJPanel5t, BorderLayout.CENTER);
                                                                   

  • Combobox autoSize to item width

    Is there a way of setting the spark ComboBox component width to fit it's labels? I am attempting to get the component to be a snug fit to its longest item label.
    Thanks in advance.

    ComboBox does not automatically size itself to fit the largest item in its dataProvider.  The closest you can come to this behavior is to use typicalItem to set the size of ComboBox based on a known object.

  • CardLayout does not work

    I'm building a dynamic UI which has "x" number of labels and "x" no of fields. I'm able build the UI.
    When I make a selection in the ComboBox the UI(labels and fields change). For this I'm using a cardlayout.
    It does not seem to work.
    AttributesPanel builds the UI(Labels, Fields)
    import java.util.*;
    import java.util.List;
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class AttributesPanel extends JPanel {
        private JTextField[] fields;
        private List attributes;
        public AttributesPanel(String templateName) throws Exception{
            JSeparator sep = new JSeparator();
            JButton okButton = new JButton("OK");
            JButton cancelButton = new JButton("Cancel");
            com.insignia.profileManagement.dataLoader.NewProfileMetaDataLoader loader = new com.insignia.profileManagement.dataLoader.NewProfileMetaDataLoader();
            attributes = loader.BuildAttributes(templateName);
            for(int i = 0; i< attributes.size(); i ++) {
              String attributename = (String)attributes.get(i);
              System.out.println("Names of the attribute: " +attributename);
            fields = new JTextField[attributes.size()];
            JLabel[] labels = new JLabel[attributes.size()];
            for(int i = 0; i< attributes.size(); i++) {
                labels[i] = new JLabel((String)attributes.get(i));
                fields[i] = new JTextField(15);
            GridBagLayout gb1 = new GridBagLayout();
            GridBagConstraints gbc = new GridBagConstraints();
            setLayout(gb1);
            gbc.anchor = GridBagConstraints.NORTHWEST;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            add(new JLabel("Assign Profile Template"), gbc);
            gbc.anchor = GridBagConstraints.NORTH;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.insets = new Insets(0,0,10,0);
            add(sep, gbc);
            gbc.anchor = GridBagConstraints.WEST;
            gbc.insets = new Insets(0,0,0,0);
            for(int i = 0;i < attributes.size(); i ++){
                gbc.gridwidth = 1;
                add(labels[i] ,gbc);
                add(Box.createHorizontalStrut(10));
                gbc.gridwidth = GridBagConstraints.REMAINDER;
                add(fields,gbc);
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(okButton);
    buttonPanel.add(cancelButton);
    gbc.anchor = GridBagConstraints.SOUTH;
    gbc.insets = new Insets(15,0,0,0);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridwidth = 7;
    add(buttonPanel,gbc);
    2nd class which calls AttributesPanel
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.lang.*;
    import java.util.*;
    import java.util.List;
    public class ProfileUI extends JPanel implements ActionListener{
    private JPanel templatePanel;
    JComboBox comboBox = new JComboBox();
    private CardLayout cardLayout;
    com.insignia.profileManagement.dataLoader.NewProfileMetaDataLoader loader = new com.insignia.profileManagement.dataLoader.NewProfileMetaDataLoader();
    public ProfileUI() throws Exception {
    templatePanel = new JPanel();
    List templates = loader.BuildTemplates();
    comboBox.addActionListener(this);
    for(int i = 0; i< templates.size(); i ++) {
    comboBox.addItem(templates.get(i));
    //attributes = loader.BuildAttributes((String)templates.get(i));
    templatePanel.add(comboBox);
    List attributes = loader.BuildAttributes("Email Template");
    // //creating no of card layouts.
    cardLayout = new CardLayout();
    JPanel mainCardPanel = new JPanel(cardLayout);
    AttributesPanel[] cardPanels = new AttributesPanel[attributes.size()];
    for (int i = 0; i < attributes.size(); i++) {
    mainCardPanel.add(cardPanels[i], i);
    // createCardPanel(cardPanels[i], (String)comboBox.getItemAt(i));
    cardLayout.show(cardPanels[i], "" + i);
    templatePanel.add(mainCardPanel);
    //updateLabel(0);
    cardLayout.show(cardPanels[0], "" + 0);
    public void actionPerformed(ActionEvent e){
    if(e.getSource() == comboBox) {
    public static void main (String args []) throws Exception {
    JFrame frame = new JFrame("ProfileUI");
    JComponent newContentPane= new ProfileUI();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // use this or a
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);
    frame.setSize(400,390);
    frame.setVisible(true);
    //frame.setResizable(false);
    thnx

    Personally, I've had numerous issues with CardLayout -- I'd suggest you try CardPanel instead:
    http://java.sun.com/products/jfc/tsc/articles/cardpanel/
    - Fromage

  • Style Font in Spark TextInput Control

    Hello!
    How can I do as the title indicates please?
    Can I do it without using a custom skin because I want to be able to change fontColor and fontStyle programatically.
    Thanks!

    You can acheive it very easily with spark textinput too. Pls check below and let me know if you have any issue.
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <fx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                [Bindable]
                private var acFontSizes : ArrayCollection = new ArrayCollection([
                    {fontSize : '12'},
                    {fontSize : '16'},
                    {fontSize : '20'},
                    {fontSize : '24'},
                    {fontSize : '28'},
                    {fontSize : '32'},
                    {fontSize : '36'},
                    {fontSize : '40'},
                    {fontSize : '44'}
            ]]>
        </fx:Script>
        <mx:VBox>
                <s:TextInput id="txtInput" width="150" height="50" text="Your Text" fontSize="{comboFontSize.selectedItem.fontSize}" color="{colorCombo.selectedColor}"/>
                <mx:HBox>
                    <s:Label text="Choose Color"/>
                    <mx:ColorPicker id="colorCombo"/>
                </mx:HBox>
                <mx:HBox>
                    <s:Label text="Choose Font Size"/>
                    <s:ComboBox id="comboFontSize" dataProvider="{acFontSizes}" labelField="fontSize" selectedIndex="0"/>
                </mx:HBox>
        </mx:VBox>
    </s:Application>
    with Regards,
    Shardul singh Bartwal

  • Saves the word Null - Using jTable!!

    Hi..
    I am using a jTable to show data to the final user, and also i added a button which save changed made on the jTable is the user modifies it!! But, if i save it with in the ms access saves the word null when it finds an empty space.. why this happens? here is the code.. and sometimes it didn't work well on somefields, that why i use vectors, and now it is working.. but i am still wondering why if a field was empty, when i click on the save button it saved the word null.
    Thanks for your attention,
    Xavier Arroyo
    * Main.java
    * Created on March 29, 2007, 7:31 AM
    package empesec;
    import java.io.IOException;
    import javax.swing.*;
    import java.sql.*;
    import java.util.Vector;
    import javax.swing.JOptionPane;// Para el MessageDialog
    import javax.swing.event.*;
    import javax.swing.DefaultCellEditor;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableColumn;
    * @author  Xavier Arroyo
    public class Main extends JFrame {
         * Creates new form Main
         int numCol;
        public Main() {
            initComponents();
         tResultado.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            setUpCategoryColumn(tResultado, tResultado.getColumnModel().getColumn(2));
            setUpSituationColumn(tResultado, tResultado.getColumnModel().getColumn(3));
            setUpDepartmentColumn(tResultado, tResultado.getColumnModel().getColumn(4));
            if (ALLOW_COLUMN_SELECTION) { // true by default
                if (ALLOW_ROW_SELECTION) {
                    //We allow both row and column selection, which
                    //implies that we *really* want to allow individual
                    //cell selection.
                    tResultado.setCellSelectionEnabled(true);
                tResultado.setColumnSelectionAllowed(true);
                ListSelectionModel colSM =
                    tResultado.getColumnModel().getSelectionModel();
                colSM.addListSelectionListener(new ListSelectionListener() {
                    public void valueChanged(ListSelectionEvent e) {
                        //Ignore extra messages.
                        if (e.getValueIsAdjusting()) return;
                        ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                        if (lsm.isSelectionEmpty()) {
                            return;
                        } else {
                            int selectedCol = lsm.getMinSelectionIndex();
                            //numCol = selectedCol;
                            /*System.out.println("Column " + selectedCol
                                               + " is now selected.");*/
                                if (ALLOW_ROW_SELECTION) { // true by default
                                    ListSelectionModel rowSM = tResultado.getSelectionModel();
                                    rowSM.addListSelectionListener(new ListSelectionListener() {
                                        public void valueChanged(ListSelectionEvent e) {
                                            //Ignore extra messages.
                                            if (e.getValueIsAdjusting()) return;
                                            ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                                            if (lsm.isSelectionEmpty()) {
                                                System.out.println("");
                                            } else {
                                                int selectedRow = lsm.getMinSelectionIndex();
                                                tIdCompu.setText("ping wna-gye-" + modeloDef.getValueAt(selectedRow,0));
                                }else {
                                tResultado.setRowSelectionAllowed(false);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            rbGroup = new javax.swing.ButtonGroup();
            jLabel1 = new javax.swing.JLabel();
            jSeparator1 = new javax.swing.JSeparator();
            textIdE = new javax.swing.JTextField();
            jLabel2 = new javax.swing.JLabel();
            bOk = new javax.swing.JButton();
            bExit = new javax.swing.JButton();
            tJSPt = new javax.swing.JScrollPane();
            tResultado = new javax.swing.JTable();
            tIdCompu = new javax.swing.JTextField();
            jLabel3 = new javax.swing.JLabel();
            bConnect = new javax.swing.JButton();
            rButton1 = new javax.swing.JRadioButton();
            rButton2 = new javax.swing.JRadioButton();
            bSave = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Consulta Activos Por Empleado");
            jLabel1.setText("Consulta de Activos por Empleados");
            jLabel2.setText("Id de Empleado :");
            bOk.setText("Aceptar");
            bOk.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    bOkMouseClicked(evt);
            bExit.setText("Borrar");
            bExit.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    bExitMouseClicked(evt);
         modeloDef = new javax.swing.table.DefaultTableModel(
              new Object [][] {
                new String [] {
                    "Codigo Barra", "Descripci?n", "Categor?a", "Situaci?n", "Departamento", "Nro. Modelo", "Nro. Serie", "Empresa", "Comentarios", "AR Number", "Sistema Operativo", "Version Office"
                boolean[] canEdit = new boolean [] {
                    false, true, true, true, true, true, true, true, true, true, true, true
         public boolean isCellEditable(int rowIndex, int columnIndex){
              return canEdit [columnIndex];
            tResultado.setModel(modeloDef);
            tJSPt.setViewportView(tResultado);
            jLabel3.setText("Command");
            bConnect.setText("Conectar");
            bConnect.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    bConnectMouseClicked(evt);
            rbGroup.add(rButton1);
            rButton1.setText("Por Apellido");
            rButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
            rButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
            rbGroup.add(rButton2);
            rButton2.setText("Por Nombre & Apellido");
            rButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
            rButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
            bSave.setText("Guardar Cambios");
            bSave.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    bSaveMouseClicked(evt);
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(tJSPt, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 668, Short.MAX_VALUE)
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 668, Short.MAX_VALUE)
                        .add(layout.createSequentialGroup()
                            .add(253, 253, 253)
                            .add(jLabel1)))
                    .addContainerGap())
                .add(layout.createSequentialGroup()
                    .add(20, 20, 20)
                    .add(jLabel2)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                        .add(layout.createSequentialGroup()
                            .add(bOk)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(bExit, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(textIdE))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                            .add(rButton1)
                            .add(53, 53, 53)
                            .add(jLabel3))
                        .add(rButton2))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(tIdCompu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 151, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(bConnect))
                    .add(87, 87, 87))
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(553, Short.MAX_VALUE)
                    .add(bSave)
                    .addContainerGap())
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(jLabel1)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jLabel2)
                        .add(textIdE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(rButton1)
                        .add(tIdCompu, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jLabel3))
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(bOk)
                            .add(bExit))
                        .add(bConnect)
                        .add(rButton2))
                    .add(23, 23, 23)
                    .add(tJSPt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 151, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(bSave)
                    .addContainerGap(27, Short.MAX_VALUE))
            pack();
        }// </editor-fold>                       
        private void bSaveMouseClicked(java.awt.event.MouseEvent evt) {                                  
    // TODO add your handling code here:
            tempDep.removeAllElements();
            tempCat.removeAllElements();
            tempSit.removeAllElements();
            actualizarDatos();
        private void bConnectMouseClicked(java.awt.event.MouseEvent evt) {                                     
            try {
    // TODO add your handling code here:
                //this.obtnerValue();
                int n = cmdPing();
                //new windowCmd(tIdCompu.getText()).setVisible(true);
                /*windowCmd ventanaPing = new windowCmd();
                ventanaPing.setTemp(tIdCompu.getText());
                ventanaPing.setearAreaTexto();
                ventanaPing.setVisible(true);*/
            } catch (Exception ex) {
                ex.printStackTrace();
        private void bExitMouseClicked(java.awt.event.MouseEvent evt) {                                  
    // TODO add your handling code here:
            limpiarTabla();
        private void bOkMouseClicked(java.awt.event.MouseEvent evt) {                                
    // TODO add your handling code here:
            if(bOk.isEnabled())
                this.bOk.setEnabled(false);
                obtenerEmpleado();
                mostrarDatos();
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Main().setVisible(true);
        public void setUpCategoryColumn(JTable table, TableColumn categoryColumn) {
            JComboBox comboBox = new JComboBox();
            Connection conn = null;
            Conexion ejSQL = new Conexion();
            String consulta="";
            ResultSet rs=null;
            Vector vCombo = new Vector();
            if(ejSQL.conectar())
                try
                    conn = ejSQL.getConexion();//obtiene la conexion
                    consulta = "SELECT CategoriaActivo FROM Categorias_de_activo";
                    rs = ejSQL.ejecutarConsulta(consulta);
                    while(rs.next())
                        vCombo.addElement(rs.getString(1));
                    for(int i=0;i<vCombo.size();i++)
                        comboBox.addItem(vCombo.get(i));
                    categoryColumn.setCellEditor(new DefaultCellEditor(comboBox));
                    //Set up tool tips for the sport cells.
                    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
                    renderer.setToolTipText("Click for combo box");
                    categoryColumn.setCellRenderer(renderer);
                    ejSQL.cerrarConexion();
                catch(SQLException e)
                        System.out.println("SQLException: " + e.getMessage());
                        while((e = e.getNextException()) != null)
                            System.out.println(e.getMessage());
         else
                System.out.println("Ha ocurrido un error con la base de datos");
        public void setUpSituationColumn(JTable table, TableColumn situationColumn) {
            JComboBox comboBox = new JComboBox();
            Connection conn = null;
            Conexion ejSQL = new Conexion();
            String consulta="";
            ResultSet rs=null;
            Vector vCombo = new Vector();
            if(ejSQL.conectar())
                try
                    conn = ejSQL.getConexion();//obtiene la conexion
                    consulta = "SELECT Situacion FROM Situacion";
                    rs = ejSQL.ejecutarConsulta(consulta);
                    while(rs.next())
                        vCombo.addElement(rs.getString(1));
                    for(int i=0;i<vCombo.size();i++)
                        comboBox.addItem(vCombo.get(i));
                    situationColumn.setCellEditor(new DefaultCellEditor(comboBox));
                    //Set up tool tips for the sport cells.
                    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
                    renderer.setToolTipText("Click for combo box");
                    situationColumn.setCellRenderer(renderer);
                    ejSQL.cerrarConexion();
                catch(SQLException e)
                        System.out.println("SQLException: " + e.getMessage());
                        while((e = e.getNextException()) != null)
                            System.out.println(e.getMessage());
         else
                System.out.println("Ha ocurrido un error con la base de datos");
        public void setUpDepartmentColumn(JTable table, TableColumn departmentColumn) {
            JComboBox comboBox = new JComboBox();
            Connection conn = null;
            Conexion ejSQL = new Conexion();
            String consulta="";
            ResultSet rs=null;
            Vector vCombo = new Vector();
            if(ejSQL.conectar())
                try
                    conn = ejSQL.getConexion();//obtiene la conexion
                    consulta = "SELECT NombreDepartamento FROM Departamentos";
                    rs = ejSQL.ejecutarConsulta(consulta);
                    while(rs.next())
                        vCombo.addElement(rs.getString(1));
                    for(int i=0;i<vCombo.size();i++)
                        comboBox.addItem(vCombo.get(i));
                    departmentColumn.setCellEditor(new DefaultCellEditor(comboBox));
                    //Set up tool tips for the sport cells.
                    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
                    renderer.setToolTipText("Click for combo box");
                    departmentColumn.setCellRenderer(renderer);
                    ejSQL.cerrarConexion();
                catch(SQLException e)
                        System.out.println("SQLException: " + e.getMessage());
                        while((e = e.getNextException()) != null)
                            System.out.println(e.getMessage());
         else
                System.out.println("Ha ocurrido un error con la base de datos");
        public void limpiarTabla(){
            this.bOk.setEnabled(true);
         this.textIdE.setText("");
            this.tIdCompu.setText("");
            int numFilas = this.tResultado.getRowCount();
            int numColumnas = this.tResultado.getColumnCount();
            vDepa.removeAllElements();
            vDescrip.removeAllElements();
            vSitua.removeAllElements();
            for(int i=0;i<numColumnas;i++)
                for(int j=0;j<numFilas;j++)
                    //modeloDef.setValueAt("",j,i);
                    modeloDef.removeRow(i);
            //System.out.println(numFilas + "+" + numColumnas);
            /*for(int i=0;i<numFilas;i++)
                System.out.println("borro " + i);
                modeloDef.removeRow(i);
                modeloDef.fireTableRowsDeleted(1,numFilas+1);
        public void obtenerEmpleado(){
            String nomEmpleado;
            nomEmpleado = textIdE.getText();
            if(rButton2.isSelected())
                obEmpleado.separarNombre(nomEmpleado);
                if (!obEmpleado.obtenerCodEmpleado()){
                    JOptionPane.showMessageDialog(null,"Usuario Incorrecto o No Existe!", "Mensaje!",JOptionPane.ERROR_MESSAGE);
                    textIdE.setText(null);
                    bOk.setEnabled(true);
            if(rButton1.isSelected())
        public int cmdPing() throws Exception
        Process p;
        int intResult;
        String strExec = new String(tIdCompu.getText());
        //p=Runtime.getRuntime().exec(strExec); // start the process
        p=Runtime.getRuntime().exec(strExec); // Modificar
        // now set something up that scans for output (independently)
        MGStreamGobbler mgSGErrors = new MGStreamGobbler(p.getErrorStream(),"error ");
        MGStreamGobbler mgSGOutput = new MGStreamGobbler(p.getInputStream(),"output ");
        // start the somethings
        mgSGErrors.start();
        mgSGOutput.start();
        // now wait for the actual process to end, wait for it's result
        intResult=p.waitFor();
        //String pruebaIP = mgSGOutput.extractIp();
        //tIdCompu.setText(pruebaIP);
        return(intResult);
       /**obtiene y ejecuta el CMD de Windows para poder obtener IP
        * de una computadora atraves del nombre de dicha maquina
        public void obtnerValue(){
                //tIdCompu.setText("ping -t wna-gye-"+obActivo.getIpCod());
            /*    Runtime r=Runtime.getRuntime (  ) ;
            try {
                Process P=r.exec(tIdCompu.getText());
            } catch (IOException ex) {
                ex.printStackTrace();
        public void mostrarDatos(){
        Connection conn = null;
        Conexion ejSQL = new Conexion();
        String consulta;
        int i=0, idEmpleado, cont = 0;
        ResultSet rs=null;
        idEmpleado = obEmpleado.getIdEmpleado();
            if(ejSQL.conectar())
                try
                    conn = ejSQL.getConexion();//obtiene la conexion
                    consulta = "SELECT act.Descripci?nActivo, cat.CategoriaActivo, sit.Situacion, dep.NombreDepartamento, act.N?mModelo, act.N?mSerie, act.C?digoDeBarras, act.Empresa, act.Comentarios_, act.Capital_Apropiation, act.Wd, act.Offi FROM Activos act, Categorias_de_Activo cat, Situacion sit, Departamentos dep WHERE act.IdEmpleado = "+idEmpleado+" And act.IdCategoriaActivo=cat.IdCategoriaActivo And act.IdSituacion = sit.IdSituacion And act.IdDepartamento=dep.IdDepartamento ORDER BY act.IdSituacion, act.IdCategoriaActivo";
                    //consulta = "SELECT DescripcionActivo FROM Activos";
                    rs = ejSQL.ejecutarConsulta(consulta);
                    while(rs.next())
                        vDescrip.addElement(rs.getString(1));
                        obActivo.setIdCategoria(rs.getString(2));
                        vSitua.addElement(rs.getString(3));
                        vDepa.addElement(rs.getString(4));
                        obActivo.setNumModelo(rs.getString(5));
                        obActivo.setNumSerie(rs.getString(6));
                        obActivo.setIdCodBarra(rs.getString(7));
                        obActivo.setEmpresa(rs.getString(8));
                        obActivo.setComentario(rs.getString(9));
                        obActivo.setArSerie(rs.getString(10));
                        obActivo.setOperativo(rs.getString(11));
                        obActivo.setOffice(rs.getString(12));
                        Object[] newRow={obActivo.getIdCodBarra(), vDescrip.get(i), obActivo.getIdCategoria(),
                        vSitua.get(i), vDepa.get(i), obActivo.getNumModelo(), obActivo.getNumSerie(),
                        obActivo.getEmpresa(), obActivo.getComentario(), obActivo.getArSerie(),
                        obActivo.getOperativo(), obActivo.getOffice()};
                        modeloDef.addRow(newRow);
                        i++;
                        cont++;
                    tResultado.updateUI();
                    ejSQL.cerrarConexion();
                catch(SQLException e)
                        System.out.println("SQLException: " + e.getMessage());
                        while((e = e.getNextException()) != null)
                            System.out.println(e.getMessage());
         else
                System.out.println("Ha ocurrido un error con la base de datos");
        public void actualizarDatos(){
            Connection conn = null;
            Conexion ejSQL = new Conexion();
            String consulta;
            //int i=0, idEmpleado, cont = 0;////////////
            ResultSet rs=null;
            //idEmpleado = obEmpleado.getIdEmpleado();//////////
            Vector tempCod = new Vector();
            Vector tempDes = new Vector();
            Vector tempMod = new Vector();
            Vector tempSer = new Vector();
            Vector tempEmp = new Vector();
            Vector tempCom = new Vector();
            Vector tempAR = new Vector();
            Vector tempOpe = new Vector();
            Vector tempOff = new Vector();
            int numFilas = this.tResultado.getRowCount();
            int numColumnas = this.tResultado.getColumnCount();
            for(int j=0;j<numFilas;j++)
                //System.out.println(numFilas +"+"+numColumnas);
                for(int k=0;k<numColumnas;k++)
                    //modeloDef.removeRow(j);
                    //System.out.println(modeloDef.getValueAt(j,k));
                    if(modeloDef.getValueAt(j,k)==null)
                        modeloDef.setValueAt("  ",j,k);
                    switch(k)
                        case 0:
                            tempCod.addElement(modeloDef.getValueAt(j,k));
                            //System.out.println(tempCod.lastElement());
                            break;
                        case 1:
                            tempDes.addElement(modeloDef.getValueAt(j,k));
                            //System.out.println(tempDes.lastElement());
                            break;
                        case 2:
                            tempCat.addElement(modeloDef.getValueAt(j,k));
                            //System.out.println(tempCat.lastElement());
                            break;
                        case 3:
                            tempSit.addElement(modeloDef.getValueAt(j,k));
                            //System.out.println(tempSit.lastElement());
                            break;
                        case 4:
                            tempDep.addElement(modeloDef.getValueAt(j,k));
                            //System.out.println(tempDep.lastElement());
                            break;
                        case 5:
                            tempMod.addElement(modeloDef.getValueAt(j,k));
                            //System.out.println(tempMod.lastElement());
                            break;
                        case 6:
                            tempSer.addElement(modeloDef.getValueAt(j,k));
                            //System.out.println(tempSer.lastElement());
                            break;
                        case 7:
                            tempEmp.addElement(modeloDef.getValueAt(j,k));
                            //System.out.println(tempEmp.lastElement());
                            break;
                        case 8:
                            tempCom.addElement(modeloDef.getValueAt(j,k));
                            //System.out.println(tempCom.lastElement());
                            break;
                        case 9:
                            tempAR.addElement(modeloDef.getValueAt(j,k));
                            //System.out.println(tempAR.lastElement());
                            break;
                        case 10:
                            tempOpe.addElement(modeloDef.getValueAt(j,k));
                            //System.out.println(tempOpe.lastElement());
                            break;
                        case 11:
                            tempOff.addElement(modeloDef.getValueAt(j,k));
                            //System.out.println(tempOff.lastElement());
                            break;
            actualizarDepartamento();
            actualizarCategoria();
            actualizarSituacion();
            if(ejSQL.conectar())
                try
                    conn = ejSQL.getConexion();//obtiene la conexion
                    for(int i=0;i<tempDep.size();i++ )
                        System.out.println(tempOff.get(i));
                        consulta = "UPDATE Activos SET Descripci?nActivo='"+tempDes.get(i)+"'  WHERE C?digoDeBarras = '"+tempCod.get(i)+"'";
                        rs = ejSQL.ejecutarConsulta(consulta);
                    for(int i=0;i<tempMod.size();i++ )
                        consulta = "UPDATE Activos SET N?mModelo='"+tempMod.get(i)+"' WHERE C?digoDeBarras = '"+tempCod.get(i)+"'";                  
                        rs = ejSQL.ejecutarConsulta(consulta);
                    for(int i=0;i<tempSer.size();i++ )
                        consulta = "UPDATE Activos SET N?mSerie='"+tempSer.get(i)+"' WHERE C?digoDeBarras = '"+tempCod.get(i)+"'";                  
                        rs = ejSQL.ejecutarConsulta(consulta);
                    for(int i=0;i<tempEmp.size();i++ )
                        consulta = "UPDATE Activos SET Empresa='"+tempEmp.get(i)+"' WHERE C?digoDeBarras = '"+tempCod.get(i)+"'";                  
                        rs = ejSQL.ejecutarConsulta(consulta);
                    for(int i=0;i<tempCom.size();i++ )
                        consulta = "UPDATE Activos SET Comentarios_='"+tempCom.get(i)+"' WHERE C?digoDeBarras = '"+tempCod.get(i)+"'";                  
                        rs = ejSQL.ejecutarConsulta(consulta);
                    for(int i=0;i<tempAR.size();i++ )
                        consulta = "UPDATE Activos SET Capital_Apropiation='"+tempAR.get(i)+"' WHERE C?digoDeBarras = '"+tempCod.get(i)+"'";                  
                        rs = ejSQL.ejecutarConsulta(consulta);
                    for(int i=0;i<tempOpe.size();i++ )
                        consulta = "UPDATE Activos SET Wd='"+tempOpe.get(i)+"' WHERE C?digoDeBarras = '"+tempCod.get(i)+"'";                  
                        rs = ejSQL.ejecutarConsulta(consulta);
                    for(int i=0;i<tempOff.size();i++ )
                        consulta = "UPDATE Activos SET Offi='"+tempOff.get(i)+"' WHERE C?digoDeBarras = '"+tempCod.get(i)+"'";                  
                        rs = ejSQL.ejecutarConsulta(consulta);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     

    Hi
    Not sure what the use case is here but what I would do is to make sure when you create the employee or whatever the salary gets initialised to 0, db trigger, default etc.
    instead of null (null values can be a PITA when you have to search on them)
    Then all you have to do is to force a numeric input, the user can type 0 for all unassigned salaries.
    This removes the problem you have of leaving the box blank and having to accept the word NULL as an input value.
    HTH
    Paul

  • ComboBox size in JTable

    How do you set the size of a combobox inside a JTable cell. I have used setPreferredWidth but the ccombo box is still huge. I have done searches and not found any answers.
    Thanks

    I've always let the UI take care of it. I don't set the minimum, maximum or preferred sizes and the UI sets the size to the size fo the cell.

  • ComboBox Problem to change the size of selected text in JTextPane.

    hi 2 all!
    I have a problem in combo box actions, when i change the item in the combo its set is not set at that time but that action is performed when next action is taken, i have used combobox.setAction(new StyledEditorKit.FontSizeAction(" click", 12);) command to set the size of the selected text
    Plz suggest the solution also if possible,plz provide some code for this
    Action action1 = new StyledEditorKit.FontSizeAction(
                                                 "double click", 12);
                                       Action action2 = new StyledEditorKit.FontSizeAction(
                                                 "double click", 14);
                                       Action action3 = new StyledEditorKit.FontSizeAction(
                                                 "double click", 18);
    s2 = (String) cb7.getSelectedItem();
                                       if (s2.equals("Small")) {
                                            cb7.setAction(action1);
                                            e1.setSource(cb7);
                                                      } else
                                       if (s2.equals("Medium")) {
                                            cb7.setAction(action2);
                                            e1.setSource(cb7);
                                                                          } else if (s2.equals("Large")) {
                                            cb7.setAction(action3);
                                            // e1.setSource(cb7);
    when i chooze any combobox item then according to that item i set the Action on ComboBox but that action is not working properly on the selected text in the JTextPane..means selected text in JText Pane is not changes its Size according to the comboBox selected ITEM.
    PLZ plzzzzzzzzzz help me:((.i will be thankfull to u.
    thanx in advance..

    this code is not working properly according to the action i set on comboBox.Thats correct, the setAction() method is used to invoke an existing Action on the combo box, not create a new Action.
    What you need to do is have a single action that uses the information from the item that was selected to build a dynamic Action to change the font. Something like:
    public void actionPerformed(ActionEvent e)
         JComboBox comboBox = (JComboBox)e.getSource();
         int fontSize = Integer.parseInt( comboBox.getSelectedItem().toString() );
         Action fontAction = new StyledEditorKit.FontSizeAction("size", fontSize);
         fontAction.actionPerformed(null);
    }

  • Is it possible to have different size for a combobox and its popup?

    Hello,
    I am showing a JComboBox with all possible fonts. Some of the font names are very long. I'd like to show a narrower combobox but when the popup menu is open to make as wide as necessary.
    Is that possible?
    Thanks.

    Hi.
    I found this a while ago, but never used it myself:// A Custom UI for the combo box popup
    private static class PopupExpandingComboBoxUI extends WindowsComboBoxUI
    protected ComboPopup createPopup()
    return new ExpandingComboPopup(comboBox);
    // Our custom popup menu - it makes up its own width
    private static class ExpandingComboPopup extends BasicComboPopup
    public ExpandingComboPopup(JComboBox cBox)
    super(cBox);
    public Rectangle computePopupBounds(int px, int py, int pw, int ph)
    // Ok - just set the popup width to 200 for now - should be calculated though
    return super.computePopupBounds(px, py, 200, ph);
    }

  • How to get the values of 2 dynamic comboboxes in one jsp to another jsp?

    I have 2 comboboxes and one submit button on my jsp page.I select a value in 1st combobox then the values in the second combobox populated from the database. next i select 2nd combobox and then submit the button.After submit the button call the next jsp page. In that page i want to display the values of two comboboxes. but my problem is , in that page only 2nd combobox value is displayed.1st combobox is displayed as null. plz tell me, how to get the values of two comboboxes at a time?
    Select.jsp:
    <%@ page language="java" import="java.sql.*" %>
    <%!
         Connection con = null;
         Statement  st  = null;
         ResultSet  rs  = null;
         String     sql = null;
         void addItems(javax.servlet.jsp.JspWriter out, String sql)
           try{     
              rs = st.executeQuery(sql);
              while( rs.next() )
                   out.println("<option>" + rs.getString(1) + "</option>");               
         }catch(Exception e)
                   System.out.println(e);
    %>
    <HTML>
    <HEAD>
    <TITLE>JSP WITH  MULTIPLE FORMS</TITLE>
    <script language="javascript">
              function checking()
                        form1.submit();
         </script>
    </HEAD>
         <body>
             <center>
             <b><font size="5" color="#333399">Staff ID:</font></b></center>
                     <FORM NAME="form1" METHOD="POST" ACTION="Select.jsp">
                         <p align=center>
                         Details of Staff :  
                       <SELECT 1 NAME="type" onchange="checking();">
                                    <option> Administrator </option>
                              <option> OfficeAssistent </option>
                              <option> Clerk </option>
                                  </SELECT 1>
                          </p>
    </FORM>
                      <FORM NAME="form2" METHOD="POST" action="welcome1.jsp">
                      <center>
                          <TABLE><TR><TD>Staff ID:</TD>
                                 <TD><SELECT 2 NAME="staff_id">
                    <%    
            String type = request.getParameter("type");
            try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            con = DriverManager.getConnection("jdbc:odbc:java","system","manager");
            catch (ClassNotFoundException ex) {
                   System.out.println(ex);
            catch (SQLException ex)
                System.out.println(ex);
         st  = con.createStatement();
         sql = "select staff_id from "+type+"";
         addItems(out, sql);
    %>
              </SELECT 2>
           </TD>
         </TR>
    </table></center>
    <h2> Details of <%= type + "s" %> </h2>
                         <center><input type=submit value=ok onclick="submit();"></center>
                  </FORM>
         </BODY>
    </HTML>
    welcome1.jsp
    <center><h1>WEL COME</h1></center>
    <%    
            String type = request.getParameter("type");
            String sid = request.getParameter("staff_id");
    %>
    <h2> Details of <%= type + "s" %> </h2>
    <h2> Details of <%= sid %> </h2>

    <SELECT 1 NAME="type" onchange="checking();">
                                    <option value = "0"> Administrator </option>
                              <option value = "1"> OfficeAssistent </option>
                              <option value = "2"> Clerk </option>
                                  </SELECT 1>

  • Problems with linked ComboBoxes

    Hi everyone, and thanks to those who will reply
    It's been 3 days since i'm having the same problem :
    I have 2 comboboxes in a JPanel, and the things to be displayed in the second one depends on the first (for example selecting 'Hewlett-Packard' in the first combo box display all HP model in the second one)
    When i select a item in the first combobox, an actionPerformed is fired, and i can populate the second combobox. Unfortunately, the combobox disappear in my panel, but if i click on the place where it used to be, the popup list display correctly... !
    I just want to know hox can i make it visible anyway. I've tried combobox2.repaint() method within the actionperformed method (combobox2 is the name of my second combo box as you've guessed), but it doesnt work...
    Something else too : in my first list, if i select another vendor, the list in the second is not removed, but the list of workstation of the second-select manufacturer is appended... I've tried here the combobox2.removeall() method, but here again, no results....
    this is my code :
    public class DocPCConfig extends JFrame implements ActionListener, WindowListener
    /** D�clare les variables utilis�es **/
    JComboBox comboConstructeurs, comboMachines;
    private JPanel imagePanel, panelConstructeur, panelMachines;
    * DocPCConfig()
    * Constructeur par d�faut
    * - But : Initialise les composants Swing de la fen�tre principale
    * - E : -/-
    * - S : -/-
    public DocPCConfig()
    /** Ajoute les composants dans l'onglet **/
    ajoutCompoCstr();
    /** Ajoute un �couteur d'�v�nement de fen�tre **/
    addWindowListener(this);
    * main()
    * - But : Point d'entr�e de l'application
    * - E : String args[] : Tableau de param�tres
    * - S : -/-
    public static void main(String args[])
    System.out.println("Lancement de l'application de configuration");
    new BdD();
    mainFrame = new DocPCConfig();
    mainFrame.setSize(1024,738);
    mainFrame.setTitle("DocPCConfig");
    mainFrame.setVisible(true);
    * ajoutCompoCstr()
    * - But : Ajoute les composants pour le panel de s�lection constructeur/machine (1er onglet)
    * - E : -/-
    * - S : -/-
    public void ajoutCompoCstr()
    java.awt.GridBagConstraints gridBagConstraints1;
    /** Cr�e le vecteur stockant les r�sultats provenant de la BdD **/
    Vector listeConstructeurs = new Vector(10,5);
    /** Se connecte � la BdD **/
    BdD.connecteBdD();
    /** R�cup�re la liste des constructeurs depuis la BdD **/
    listeConstructeurs = BdD.getConstructeurs();
    DefaultComboBoxModel comboModele = new DefaultComboBoxModel(listeConstructeurs);
    BdD.deconnecteBdD();
    /** Lance le constructeur pour la liste d�roulante avec le vecteur de liste
    comme param�tre **/
    comboConstructeurs = new JComboBox(comboModele);
    /** R�gle les param�tres suppl�mentaires **/
    comboConstructeurs.setMaximumSize(new Dimension(5,5));
    comboConstructeurs.setSelectedIndex(-1);
    // comboConstructeurs.setEditable(true);
    /** Ajoute les contraintes graphiques pour la liste des constructeurs **/
    gridBagConstraints1 = new GridBagConstraints();
    gridBagConstraints1.gridx = 1;
    gridBagConstraints1.gridy = 1;
    gridBagConstraints1.insets = new Insets(10, 10, 10, 10);
    panelConstructeur.add(comboConstructeurs, gridBagConstraints1);
    comboConstructeurs.addActionListener(this);
    /** Cr�e les �l�ments de la liste d�roulante **/
    String[] listeMachines = { "                             " };
    comboMachines = new JComboBox(listeMachines);
    comboMachines.setSelectedIndex(0);
    /** Ajoute les contraintes graphiques pour la liste des machines **/
    gridBagConstraints1 = new GridBagConstraints();
    gridBagConstraints1.gridx = 1;
    gridBagConstraints1.gridy = 2;
    gridBagConstraints1.insets = new Insets(10, 10, 10, 10);
    panelConstructeur.add(comboMachines, gridBagConstraints1);
    * actionPerformed(ActionEvent ae)
    * - But : Traiter les op�ration quand une action est effectu�e sur les boutons
    * de l'interface de la fen�tre principale.
    * - E : ActionEvent ae : Un pointeur sur l'action courante.
    * - S :-/-
    public void actionPerformed(ActionEvent ae)
    Object source = ae.getSource();
    /** Liste d�roulante des constructeurs **/
    if (source == comboConstructeurs)
    /** R�cup�re la ligne s�lectionn�e dans la liste **/
    String constructeur = (String)comboConstructeurs.getSelectedItem();
    /** Creation des �l�ments de la liste d�roulante **/
    Vector listeMachines = new Vector(50,1);
    /** Se connecte � la BdD **/
    BdD.connecteBdD();
    listeMachines = BdD.getMachines(constructeur);
    /** Se d�connecte de la BdD **/
    BdD.deconnecteBdD();
    /** Supprime toutes les pr�c�dentes entr�es de la liste des machines **/
    comboMachines.removeAll();
    int i = 0;
    System.out.println(listeMachines.size());
    /** Tant que la liste n'a pas �t� parcourue **/
    while(i < listeMachines.size())
    /** Copie l'�l�ment du vecteur et l'ajoute dans la liste d�roulante **/
    comboMachines.addItem(listeMachines.elementAt(i).toString());
    i++;
    comboMachines.repaint();
    I've removed all the things I found useless, but maybe i've removed too much ;-) I hope that this code is enough.
    Thanks for your help (can you send a copy of your answers at : [email protected] - if you're too lazy to do this that's not a matter, but i don't know how i can find my post in all these posts... so that'd be cool ;-)

    Thanks Martin
    that makes sense now was driving me mad as I couldnt find anything saying it wasnt supported, makes sense seeing as its a flash server. Annoyning thing was it was playing in the content viewer locally when I previewd the folio you would think that would not be the case if it was not supported. Im going to try the rtmp links in a player in a web page and view it on the ipad out of curiosity and ill let you know. Out of interest have you done anyting with imported html into indesign as part of your folios ? I havent as yet but am curious to know how it holds up ?
    Thanks again
    Neil

  • Length of a string in a combobox exceeds the width of the combobox

    How do you fix this:
    The length of a string in a combobox exceeds the width of the combobox and as a result, the comboBox changes its size :-(
    I don't want it to change the size even if the length of the string exceeds the width of the comboBox
    what should i do?

    ok i got it
              Dimension d =combo.getPreferredSize();
    combo.setPreferredSize(new Dimension(50, d.height));
    anyone with better solution?

  • How do I change the selected text of a combobox on the fly?

    Hi all,
    I am trying to make a combobox, that is sort of a "recently used" connection box. So you can type in a computer name, hit connect and it then connects. When you disconnect, it adds the computer name, and the logged in username to the combobox,
    so when you click on the drop down, you get selections for example : "COMPUTER1 - johnsmith"
    Which is cool, but what I want, is to be able to click on the selection, and it only puts the computer name in the TextBox - i.e. "COMPUTER1"
    So I have done a bit of research, and tried making a hashtable, and using the DisplayMember and ValueMember properties, so i can at least have a combobox selection like "COMPUTER1 (johnsmith)". I have tried many different pages and suggestions,
    but the furtherest I have got is to only have one or the other value display, or it displays as System.Collection...... (can't remember the rest).
    So my next attempt, is using an event handler for the combobox to change the text, so that once "COMPUTER1 - johnsmith" is selected from the combobox, it puts "COMPUTER1" as the selected text.
    I have tried the following using the SelectedIndexChanged handler. Here is a snippet of my code relating to the ComboBox:
    # PC Connection Input Box$global:pcInputBox = New-Object System.Windows.Forms.ComboBox
    $global:pcInputBox.Location = New-Object System.Drawing.Size(70,50)
    $global:pcInputBox.Size = New-Object System.Drawing.Size(210,20)
    $global:pcInputBox_SelectedIndexChanged = {
    if (($global:pcInputBox.Text -ne $null) -and ($global:pcInputBox.Text -ne "")){
    $selection = $global:pcInputBox.Text
    addLog("Selection is $selection")
    $global:trimSelection = $selection.substring(0,$selection.indexof("-"))
    addLog("TrimSelection is $global:trimSelection")
    $global:pcInputBox.SelectedItem = $global:trimSelection
    addLog("SelectedText is $global:pcInputBox.SelectedItem")
    $global:pcInputBox.add_GotFocus({
    $Form.AcceptButton = $pcButton
    $global:pcInputBox.add_SelectedIndexChanged($global:pcInputBox_SelectedIndexChanged)
    $Form.Controls.Add($global:pcInputBox)
    I have also tried setting the $global:pcInputBox.Text but the result is that nothing changes. Its as though I can't change that ComboBox from its own event?? If I try setting $global:pcInputBox.Text from another function, it will do it fine.
    Can anyone please recommend how I would get this achieved?
    Thanks in advance
    Adam Street

    Use objects:
    $o=@()
    $o+=New-Object PsObject -Property @{Computer='COMP1';User='USER01'}
    $o+=New-Object PsObject -Property @{Computer='COMP2';User='USER02'}
    $o+=New-Object PsObject -Property @{Computer='COMP3';User='USER03'}
    $combobox1.DataSource=[collections.arraylist]($o|select Computer,User, @{N='DisplayName';E={"$($_.Computer)-$($_.User)"}})
    $combobox1.DisplayMember='DisplayName'
    This can also be loaded from a CSV or from AD or almost anywhere else;
    Here is another trivial example:
    $o=@()
    $o+=New-Object PsObject -Property @{Computer='COMP1';User='USER01'}
    $o+=New-Object PsObject -Property @{Computer='COMP2';User='USER02'}
    $o+=New-Object PsObject -Property @{Computer='COMP3';User='USER03'}
    Add-Type -AssemblyName System.Windows.Forms
    $form=New-Object System.Windows.Forms.Form
    $form.StartPosition='CenterScreen'
    $combobox1 = New-Object System.Windows.Forms.ComboBox
    $combobox1.Location='70,50'
    $combobox1.Size='210,20'
    $combobox1.DataSource=[collections.arraylist]($o|select Computer,User, @{N='DisplayName';E={"$($_.Computer)-$($_.User)"}})
    $combobox1.DisplayMember='DisplayName'
    $combobox1.add_SelectedIndexChanged({[System.Windows.Forms.MessageBox]::Show($combobox1.SelectedItem.Computer)})
    $form.Controls.Add($combobox1)
    $form.ShowDialog()
    ¯\_(ツ)_/¯

Maybe you are looking for