JComboBox Mystery

I have a main JCombobox in a JFrame that starts up with a set of values. When a user selects an item from the main JComboBox (i.e actionListener, actionPerformed(ActionEvent ae), two other JComboBoxes are filled up with values. Note that the two JComboBoxes did not have any values initially. I am using the removeAllItems() method before I populate the two JComboBoxes.
My problem is that the values get added to the JComboBoxes more than once, if I use jcbox.addItem(<value>). Instead I tried jcbox.insertItemAt(<value>) and the earlier problem is solved.
Now the new problem is that I do not know if the values have been added to the JComboBoxes until I click on the arrow to pull down the list of the JComboBoxes. Generally the first value in the list is shown at the top always as default.
The other problem is that on selection on any item in any of the two JComboBoxes, it does not appear on the top of the list and doesn't even appear to be selected at all.
Some one please advice what could be done. I need to work on this ASAP.
All the info I can get would be helpful. Thanks

Dear Thomas,
what do you mean, you don't know if the values have been added? didn't your code add them?If you had read thourgh the message properly you wouldn't need to ask this question.
can you send some code snippet how you setup your 2 jcb'sI have worked out the problem. Right now I have implemented ItemListenerinterface. I have called the itemStateChanged(ItemEvent ie) method. Inside which I have a code that handles my problem real well.
It is:
if (ie.getSource() == jcbox && ie.getSelectedItem() == ItemEvent.SELECTED){ }
Thanks Thomas anyway. UI have added this code so that other's may refer to it.

Similar Messages

  • Why do I have mysterious cellular data usage (Verizon) every 6 hours on all 3 of my iphone 5's?

    I have recently uncovered mysterious cellular usage on three different iPhones. I am a Verizon customer and discovered this by examining the cellular data use logs. What I found are a long series of mysterious data usage logs. I have visited the Genius Bar at my local Apple Store 3 times now to log notes and discuss the issue. It is being escalated.
    The characterstics are as follows:
    All my family phones have the appropriate IOS and hardware updates (verified by the GeniusBar at my local Apple Store).
    This is occuring across three phones, which happen to all be iphone 5. Two are 5 and the other a new 5s. We do have one iphone 4 in the family but the issue (so far as I can tell), is not happening on it.
    One iphone 5 has IOS 7, the other IOS 6. The new 5s has of course IOS 7.
    Mysterious data use happens even while connected to wifi.
    Each mysterious data use log entry is exactly 6 hours apart. For example: 2:18 AM, 8:18 AM, 2:18 PM, 8:18 PM, 2:18 AM ... etc. It cycles AM and PM, same times, for a day to many days until some condition causes it to change (evolve).
    The times evolve. One day it could be cycling through at one time series, then it changes to another time sequence and continues until the next condition.
    The data usage is anywhere from a few K to many MB. The largest I've seen is over 100 MB.
    The logs clearly show these usages are not due to human interaction. It is a program.
    If cellular connection is used frequently (by the owner), the pattern is hard to pick out. Luckily, my family member is very good about only using wifi whenever possible, so these mysterious use patterns are easy to pick out.
    Verizon allows access to 90 days worth of data logs, so I downloaded and analyzed them. This has been happening for at least 90 days. I have found 298 instances of mysterious use out of 500 total connections to cellular. A total of 3.5 GB of mysterious cellular data has been recorded as used in that 90 days by this phone alone. Only .6 GB of the total cellular data use is legitimate, meaning by the person.
    This issue is occuring across three different phones. Two are iPhone 5, and the third is a recently purchased iPhone 5s. The 5s I have not touched beyone the basic startup. I have left it alone on a desk for 3 days, and looking at the logs, the mysterious data use in the same pattern is occuring.
    So ... I am speaking to both sides, Verizon and Apple to get answers. Verizon puts their wall up at data usage. It doesn't matter how it is being used, you simply need to pay for it. Yes, the evidence I have gathered is getting closer to someting on Verizon's end.
    Before pressing in that direction, I am hoping someone reading this may recognize this issue as a possible iPhone 5 issue ... OR ... you, right now, go look at your data usage logs available through your carrier's web account, and see if you can pick out a pattern of mysterious use. Look especially at the early morning instances when you are most likely sleeping.
    I am hoping this is a simple issue that has a quick resolution. I'm looking for the "ooohhh, I see that now ..." But I am starting to think this might be much bigger, but the fact is, most customers rarely or never look at their data usage details, much less discover mysterious use patterns.
    The final interesting (maybe frightening part) thing about all this is that I discovered while talking to Verizon ... they do not divulge which direction the data is going. This goes for any use, mysterious or legitimate. Is cellular data coming to your phone, or leaving it? Is something pulling data from your phone? We know that it is possible to build malware apps, but the catch with my issue is that it is also happening on a brand new iphone 5s with nothing downloaded to it.
    Thanks for your time

    Thanks for the replies. It took a while not hearing anything so thought I was alone. I have done many of the suggestions already. The key here is that it occurs on both phones with apps, and phones still packaged in a box.
    A Genius Bar supervisor also checked his Verizon data usage log and found the same 6 hour incremental use. Suprisingly, he did not express much intrigue over that. Maybe he did, but did not show it.
    I think the 6 hour incremental usage is the main issue here. I spoke with Verizon (again) and they confirmed that all they do is log exactly when the phone connected to the tower and used data. The time it records is when the usage started. I also found out that the time recorded is GMT.
    What is using data, unsolicited, every 6 hours?
    Why does it change?
    Why does it only happen on the iPhone 5 series and not the 4?
    Since no one from Apple seems to be chiming in on this, and I have not received the promised calls from Apple tech support that the Genius Bar staff said I was suppose to receive, it is starting to feel like something is being swept under the rug.
    I woke up the other day with another thought ... What application would use such large amounts of data? Well ... music, video, sound and pictures of course. Well ... what would someone set automatically that is of any use to them? hmmm ... video, pictures, sound. Is the iPhone 5 succeptible to snooping? Can an app be buried in the IOS that automatically turns on video and sound recording, and send it somewhere ... every 6 hours? Chilling. I noted that the smallest data usage is during the night when nothing is going on, then it peaks during the day. The Genius Bar tech and I looked at each other when I drew this sine wave graph on the log print outs during an appointment ...

  • USB 6009 - mysterious problem

    Have mysterious problems with my new USB 6009.
    I'm using LabView 7 on MacOS-X 10.3.8.
    All vi's of DAQmx show "ERROR 15 - Ressource not found".
    Then I tested:
    - "lsdaq" shows the device
    - "nidatalogger" works
    - "mxbaseconfig" doesn't recocgnize it!
    I realy have no idea know what to do now?
    Thank you for helping.
    Greetings,
    Stephan

    I happend to stumble over the same issue and found a solution.
    The problem really seems to be the firmware in the USB-device. There is
    only one way (I think) to make USB600x devices work with linux:
    You have to start MAX (on a Windows-box) , go to tools - NI-DAQmx configuration - NI-DAQmx USB Driver Selector.
    Press "Switch" and select the BASE-Driver for your USB-Device. This
    seems to write something into the device's flash memory. After this
    procedure you can use the device with linux and DAQmxBase
    Funny thing is, mxbaseconfig still can't see it, but nidatalogger finds it.
    Hope that helps, even though this thread seems to be rather old...
    -DB

  • Random (mysterious) start-ups from shutdown on MBP 17" (Hi-Res)

    Hi,
    lately, my MBP has started to turn itself on at night. I always shut it down completely after a days' work (NOT making it sleep or standby, also NOT closing the lid before the shutdown is done). Actually, I tried waiting 5-10 minutes before closing the lid after the shutdown just to make sure I wasn't interrupting anything.
    Now, in the morning, my MBP sits there sleeping (the light on the front is in "breathing" mode), and after opening the lid it is completely booted up.
    Syslog shows me it randomly started at some time in the night (between 1h and 5h hours after the shutdown.
    Of course I made sure that I have not set a startup time in the power setting's scheduler.
    What could be the reason for this?

    My MBP 15in also mysteriously self-starts. I have determined that this occurs every evening at 7:00 pm sharp when the AC power is attached. This is despite the fact that I have no scheduled start-up time configured. I have yet to have it happen on battery. It has been happening regularly when nothing else is plugged in, not USB, FW, nothing. Sharing and remote management may be turned on or off as otherwise needed and have no noticed influence.

  • Mysterious Teardown Problem with NIO

    I have an NIO proxy server which relays state information from a number of servers to a number of clients. A requirement for this system is that we can restart the proxy server (together with a couple of other components) from a web app.
    I tear down the proxy server by
    - interrupting out of the read loop
    - cancelling all keys associated with the channel
    - closing the socket on the channel
    - closing the channel.
    I do this for for both the input (server side) channel and the output (client side) channel.
    I then discard the proxy server, create a new one and start it up.
    Now here's the mysterious bit. The new server operates just fine for a minute or two. And then it stops seeing any input.
    The thread responsible for input reading freezes on the call to -
    myKeysAdded = myAcceptKey.selector().select();and the stack looks something like this:
    WindowsSelectorImpl$SubSelector.poll0(long, int, int[], int[], int[], long)
    WindowsSelectorImpl$SubSelector.poll() line: 270
    WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl$SubSelector) line: 252
    WindowsSelectorImpl.doSelect(long) line: 133
    WindowsSelectorImpl(SelectorImpl).lockAndDoSelect(long) line: 69
    WindowsSelectorImpl(SelectorImpl).select(long) line: 80
    WindowsSelectorImpl(SelectorImpl).select() line: 84
    ProxyServer$BrowserSelector.run() line: 123If I completely destroy the process (and the jvm) and start a new one everything goes back to working normally.
    Has anyone got any suggestions? I'm in hair-tearing mode on this one.
    Thx TOTW.

    I tear down the proxy server by
    - interrupting out of the read loopDon't you mean the select() loop?
    - cancelling all keys associated with the channelUnnecessary.
    - closing the socket on the channel
    - closing the channel.Only one of these is necessary. Closing the socket closes the channel and vice versa.
    When you have closed all the channels, you then need to call selector.selectNow() (search this forum for why), and then close the selector.

  • Mysterious Data Usage

    Hello,
    My wife owns an HTC Thunderbolt.  We are experiencing mysterious data usage. 
    The data log shows data usage during hours and at times when the phone is not being used.  We have tried closing all apps and resetting the phone.
    Still, these nickel and dime data used entries are adding up fast and bring us to the brink of our our plan which we have already extended.
    We do not stream video, we do not listen to Pandora.... The phone is used strictly for texts, emails, and phone calls.
    Any advice?  Thank you for your help.

    Same here - very similar.Times are close but not like yours.
    I've deleted the email accounts and re-added them to see if there was a looping email send issue that I've read about.
    Funny though, when I review the data use on the phone, "photo" is the app indicating using the most data. So I've turned off and uninstalled everything I can think is tied to that.

  • Mysterious forces changing backlight brightness

    Some mysterious forces are changing my laptop's brightness and I can't seem to figure it out what it is.
    For example, if my battery gets below 10% (also, why 10%?), it automatically changes brightness to something very low.
    Similarly, if battery gets fully charged, it changes brightness. It also happens when I plug it into the AC or remove the adapter.
    I've looked everywhere, tried changing settings (I really don't remember which ones anymore), but nothing seems to work.
    Also, I've xfce4-power-manager installed, but closing it doesn't seem to effect this backlight changing.
    Laptop-mode-tools is also set up, but backlight control is disabled.
    My only idea is that it's changed by the driver, but how can I control it?
    edit:
    [soz@arch ~]$ lspci | grep VGA
    00:02.0 VGA compatible controller: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller (rev 09)
    Also, changing backlight to vendor doesn't fix this. Instead it messes up xfce4-power-manager's backlight control.
    Forgot to mention, I'm running a simple Openbox installation.
    Last edited by socials (2013-11-15 20:47:44)

    Alright, an update.
    The same thing happens even without running X at all. Even the brightness control keyboard hotkeys work without an X server running.
    So it seems that they interact directly with hardware and it's not related to software at all. I think it's safe to say that the brightness change events happening on charger plug/unplug are related to this as well.
    So if there's nothing in BIOS (I checked) I guess it's not fixable. I could set up an dirty hack using acpi handler scripts although it seems like an awful solution.
    Or have you guys any other ideas?

  • Not Updating the Values in the JComboBox and JTable

    Hi Friends
    In my program i hava Two JComboBox and One JTable. I Update the ComboBox with different field on A Table. and then Display a list of record in the JTable.
    It is Displaying the Values in the Begining But when i try to Select the Next Item in the ComboBox it is not Updating the Records Eeither to JComboBox or JTable.
    MY CODE is this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.DefaultComboBoxModel.*;
    import javax.swing.table.*;
    import java.sql.*;
    import java.util.*;
    public class SearchBook extends JDialog implements ActionListener
         private JComboBox comboCategory,comboAuthor;
         private JSplitPane splitpane;
         private JTable table;
         private JToolBar toolBar;
         private JButton btnclose, btncancel;
         private JPanel panel1,panel2,panel3,panel4;
         private JLabel lblCategory,lblAuthor;
         private Container c;
         //DefaultTableModel model;
         Statement st;
         ResultSet rs;
         Vector v = new Vector();
         public SearchBook (Connection con)
              // Property for JDialog
              setTitle("Search Books");
              setLocation(40,110);
              setModal(true);
              setSize(750,450);
              // Creating ToolBar Button
              btnclose = new JButton(new ImageIcon("Images/export.gif"));
              btnclose.addActionListener(this);
              // Creating Tool Bar
              toolBar = new JToolBar();
              toolBar.add(btnclose);
              try
                   st=con.createStatement();
                   rs =st.executeQuery("SELECT BCat from Books Group By Books.BCat");
                   while(rs.next())
                        v.add(rs.getString(1));
              catch(SQLException ex)
                   System.out.println("Error");
              panel1= new JPanel();
              panel1.setLayout(new GridBagLayout());
              GridBagConstraints c = new GridBagConstraints();
              c.fill = GridBagConstraints.HORIZONTAL;
              lblCategory = new JLabel("Category:");
              lblCategory.setHorizontalAlignment (JTextField.CENTER);
              c.gridx=2;
              c.gridy=2;
              panel1.add(lblCategory,c);
              comboCategory = new JComboBox(v);
              comboCategory.addActionListener(this);
              c.ipadx=20;
              c.gridx=3;
              c.gridwidth=1;
              c.gridy=2;
              panel1.add(comboCategory,c);
              lblAuthor = new JLabel("Author/Publisher:");
              c.gridwidth=2;
              c.gridx=1;
              c.gridy=4;
              panel1.add(lblAuthor,c);
              lblAuthor.setHorizontalAlignment (JTextField.LEFT);
              comboAuthor = new JComboBox();
              comboAuthor.addActionListener(this);
              c.insets= new Insets(20,0,0,0);
              c.ipadx=20;
              c.gridx=3;
              c.gridy=4;
              panel1.add(comboAuthor,c);
              comboAuthor.setBounds (125, 165, 175, 25);
              table = new JTable();
              JScrollPane scrollpane = new JScrollPane(table);
              //panel2 = new JPanel();
              //panel2.add(scrollpane);
              splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panel1,scrollpane);
              splitpane.setDividerSize(15);
              splitpane.setDividerLocation(190);
              getContentPane().add(toolBar,BorderLayout.NORTH);
              getContentPane().add(splitpane);
         public void actionPerformed(ActionEvent ae)
              Object obj= ae.getSource();
              if(obj==comboCategory)
                   String selecteditem = (String)comboCategory.getSelectedItem();
                   displayAuthor(selecteditem);
                   System.out.println("Selected Item"+selecteditem);
              else if(obj==btnclose)
                   setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
              else if(obj==comboAuthor)
                   String selecteditem1 = (String)comboAuthor.getSelectedItem();
                   displayavailablity(selecteditem1);
                   //System.out.println("Selected Item"+selecteditem1);
                   System.out.println("Selected Author"+selecteditem1);
         private void displayAuthor(String selecteditem)
              try
              {     Vector data = new Vector();
                   rs= st.executeQuery("SELECT BAuthorandPublisher FROM Books where BCat='" + selecteditem + "' Group By Books.BAuthorandPublisher");
                   System.out.println("Executing");
                   while(rs.next())
                        data.add(rs.getString(1));
                   //((DefaultComboBoxModel)comboAuthor.getModel()).setVectorData(data);
                   comboAuthor.setModel(new DefaultComboBoxModel(data));
              catch(SQLException ex)
                   System.out.println("ERROR");
         private void displayavailablity(String selecteditem1)
                   try
                        Vector columnNames = new Vector();
                        Vector data1 = new Vector();
                        rs= st.executeQuery("SELECT * FROM Books where BAuthorandPublisher='" + selecteditem1 +"'");     
                        ResultSetMetaData md= rs.getMetaData();
                        int columns =md.getColumnCount();
                        String booktblheading[]={"Book ID","Book NAME","BOOK AUTHOR/PUBLISHER","REFRENCE","CATEGORY"};
                        for(int i=1; i<= booktblheading.length;i++)
                             columnNames.addElement(booktblheading[i-1]);
                        while(rs.next())
                             Vector row = new Vector(columns);
                             for(int i=1;i<=columns;i++)
                                  row.addElement(rs.getObject(i));
                             data1.addElement(row);
                             //System.out.println("data is:"+data);
                        ((DefaultTableModel)table.getModel()).setDataVector(data1,columnNames);
                        //DefaultTableModel model = new DefaultTableModel(data1,columnNames);
                        //table.setModel(model);
                        rs.close();
                        st.close();
                   catch(SQLException ex)
    }Please check my code and give me some Better Solution
    Thank you

    You already have a posting on this topic:
    http://forum.java.sun.com/thread.jspa?threadID=5143235

  • JComboBox causing GTK-WARNING and GTK-CRITICAL on Ubuntu 8.04

    I was wondering why whenever I use the GTK Look and Feel, my JComboBox's cause GTK issues. They also don't display right...
    Here is the code I am using....
    import javax.swing.*;
    public class ComboBoxDisplayTest extends JFrame
      public ComboBoxDisplayTest()
        try
          UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
          SwingUtilities.updateComponentTreeUI(this);
        catch(Exception ex)
          ex.printStackTrace();
        JComboBox cb = new JComboBox();
        this.add(cb);
        cb.addItem("Item 1");
        cb.addItem("Item 2");
      public static void main(String[] args)
        ComboBoxDisplayTest c = new ComboBoxDisplayTest();
        c.pack();
        c.setVisible(true);
    }This is what get's printed onto the terminal when I run the program:
    java ComboBoxDisplayTest
    (<unknown>:7078): Gtk-WARNING **: Attempting to add a widget with type GtkButton to a GtkComboBoxEntry (need an instance of GtkEntry or of a subclass)
    (<unknown>:7078): Gtk-CRITICAL **: gtk_widget_realize: assertion `GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failed
    (<unknown>:7078): Gtk-CRITICAL **: gtk_paint_box: assertion `style->depth == gdk_drawable_get_depth (window)' failedWhat exactly is going on?
    Is there something wrong with my code?
    Is there any way to fix this?
    Any answers are much appreciated...
    Thanks

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6624717
    as far as i know (i am using Ubuntu 7.10 & OpenJDK 1.6.0_0-b11 & Sun JDK) not fixed yet ....
    Ronald

  • Associate Action with jcombobox item

    Is it possible to associate a particular Action with a jcombobox item (for example using setAction()). When the user selects a particular item of jcombobox, the Action must be triggered.
    regards,
    Nirvan.

    Hi,
    You can associate a particular action with a JComboBox. As per my understanding u can add one action perfrom action to combobox or itemStateChanged action
    if u add action perform action, u need to add the following method to ur logic.
    JComboBox combobox=new JComboBox();
        combobox.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
             JComboBox combo = (JComboBox)evt.getSource();
                if(combo.getSelectedItem().equals("LOCATION")) {
                A a = new A();
                a.show();
            } else if(combo.getSelectedItem().equals("HOUSE")) {
                B b= new B();
                b.show();
            });if action is ItemStateChanged then add the following method.
    combobox.addItemListener(new java.awt.event.ItemListener() {
                public void itemStateChanged(java.awt.event.ItemEvent evt) {
                    and write your logic here which one needs to be triggered when this action performed.
            });Hope this will help to you....
    Thanks & Regards,
    Maadhav..

  • Retrieving values from a JComboBox - Design question.

    I would like some design guidance on a problem that I am hoping has been solved before. Here is my situation:
    I have a JComboBox that I populate with String values from a database table. The exact set of values to be loaded into the JComboBox varies according values specified elsewhere on the GUI.
    When I select an item from the JComboBox, I need to read the database to retrieve more information. The text is not sufficient for me to identify the data I need, so I need to get the table key from somewhere.
    Is there anyway I can associate my table key with the text value inside the JComboBox and retrieve it when the user selects a drop down value from the JComboBox?
    Many thanks in advance.

    when you load the data from the db, try to get ALL the information needed: item label+item value+description. put this data into a map (a hashmap) for example using a unique identifier. For example, use a numeric index. In this case, the item value should be the index that uniquely identifies your items.
    create a simple bean that encapsulates the item contents: index+value+label, description.
    Doing this will avoid the huge db access occurences.
    hth

  • How to change font/ font color etc in a graphic object using JCombobox?

    Hello
    My program im writing recently is a small tiny application which can change fonts, font sizes, font colors and background color of the graphics object containing some strings. Im planning to use Jcomboboxes for all those 4 ideas in implementing those functions. Somehow it doesnt work! Any help would be grateful.
    So currently what ive done so far is that: Im using two classes to implement the whole program. One class is the main class which contains the GUI with its components (Jcomboboxes etc..) and the other class is a class extending JPanel which does all the drawing. Therefore it contains a graphics object in that class which draws the string. However what i want it to do is using jcombobox which should contain alit of all fonts available/ font sizes/ colors etc. When i scroll through the lists and click the one item i want - the graphics object properties (font sizes/ color etc) should change as a result.
    What ive gt so far is implemented the jcomboboxes in place. Problem is i cant get the font to change once selecting an item form it.
    Another problem is that to set the color of font - i need to use it with a graphics object in the paintcomponent method. In this case i dnt want to create several diff paint.. method with different property settings (font/ size/ color)
    Below is my code; perhaps you'll understand more looking at code.
    public class main...
    Color[] Colors = {Color.BLUE, Color.RED, Color.GREEN};
            ColorList = new JComboBox(Colors);
    ColorList.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ev) {
                     JComboBox cb = (JComboBox)ev.getSource();
                    Color colorType = (Color)cb.getSelectedItem();
                    drawingBoard.setBackground(colorType);
              });;1) providing the GUI is correctly implemented with components
    2) Combobox stores the colors in an array
    3) ActionListener should do following job: (but cant get it right - that is where my problem is)
    - once selected the item (color/ font size etc... as i would have similar methods for each) i want, it should pass the item into the drawingboard class (JPanel) and then this class should do the job.
    public class DrawingBoard extends JPanel {
           private String message;
           public DrawingBoard() {
                  setBackground(Color.white);
                  Font font = new Font("Serif", Font.PLAIN, fontSize);
                  setFont(font);
                  message = "";
           public void setMessage(String m) {
                message = m;
                repaint();
           public void paintComponent(Graphics g) {
                  super.paintComponent(g);
                  //setBackground(Color.RED);
                  Graphics2D g2 = (Graphics2D) g;
                  g2.setRenderingHint             
                  g2.drawString(message, 50, 50);
           public void settingFont(String font) {
                //not sure how to implement this?                          //Jcombobox should pass an item to this
                                   //it should match against all known fonts in system then set that font to the graphics
          private void settingFontSize(Graphics g, int f) {
                         //same probelm with above..              
          public void setBackgroundColor(Color c) {
               setBackground(c);
               repaint(); // still not sure if this done corretly.
          public void setFontColor(Color c) {
                    //not sure how to do this part aswell.
                   //i know a method " g.setColor(c)" exist but i need to use a graphics object - and to do that i need to pass it in (then it will cause some confusion in the main class (previous code)
           My problems have been highlighted in the comments of code above.
    Any help will be much appreciated thanks!!!

    It is the completely correct code
    I hope that's what you need
    Just put DrawingBoard into JFrame and run
    Good luck!
    public class DrawingBoard extends JPanel implements ActionListener{
         private String message = "message";
         private Font font = new Font("Serif", Font.PLAIN, 10);
         private Color color = Color.RED;
         private Color bg = Color.WHITE;
         private int size = 10;
         public DrawingBoard(){
              JComboBox cbFont = new JComboBox(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
              cbFont.setActionCommand("font");
              JComboBox cbSize = new JComboBox(new Integer[]{new Integer(14), new Integer(13)});
              cbSize.setActionCommand("size");
              JComboBox cbColor = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbColor.setActionCommand("color");
              JComboBox cbBG = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbBG.setActionCommand("bg");
              add(cbFont);
              cbFont.addActionListener(this);
              add(cbSize);
              cbSize.addActionListener(this);
              add(cbColor);
              cbColor.addActionListener(this);
              add(cbBG);
              cbBG.addActionListener(this);
         public void setMessage(String m){
              message = m;
              repaint();
         protected void paintComponent(Graphics g){
              super.paintComponent(g);
              Graphics2D g2 = (Graphics2D)g;
              g2.setColor(bg);//set background color
              g2.fillRect(0,0, getWidth(), getHeight());          
              g2.setColor(color);//set text color
              FontRenderContext frc = g2.getFontRenderContext();
              TextLayout tl = new TextLayout(message,font,frc);//set font and message
              AffineTransform at = new AffineTransform();
              at.setToTranslation(getWidth()/2-tl.getBounds().getWidth()/2,
                        getWidth()/2 + tl.getBounds().getHeight()/2);//set text at center of panel
              g2.fill(tl.getOutline(at));
         public void actionPerformed(ActionEvent e){
              JComboBox cb = (JComboBox)e.getSource();
              if (e.getActionCommand().equals("font")){
                   font = new Font(cb.getSelectedItem().toString(), Font.PLAIN, size);
              }else if (e.getActionCommand().equals("size")){
                   size = ((Integer)cb.getSelectedItem()).intValue();
              }else if (e.getActionCommand().equals("color")){
                   color = (Color)cb.getSelectedItem();
              }else if (e.getActionCommand().equals("bg")){
                   bg = (Color)cb.getSelectedItem();
              repaint();
    }

  • Why does a mystery application try to open when I login?

    I wonder if anyone can help me with an issue I'm having with a mystery application trying to open.
    Every time I wake my iBook G4 from sleep, or I start it from shutdown (I am the only user), I see an application is trying to open at the right side of the dock. It shows as the generic application "A" starting to open, but then it suddenly vanishes. On the advice of a Mac-user friend, I went to System Preferences/Accounts/Login Items and removed everything there, then rebooted my machine, but I still have the same problem.
    From my unfortunate experiences with PCs, I remember this type of login behavior usually indicates the machine is infected with a virus. Is that what is causing my iBook problem? I have the Firewall turned on, and I'm running Norton Antivirus for Mac (which has found nothing in repeated scans). What should I try next? Any help with this would be really appreciated.
    iBook G4   Mac OS X (10.4.6)  
    iBook G4   Mac OS X (10.4.6)  

    It's difficult to say what the application may be if you can't see its name, but in the Dock, the name won't show unless you are pointing at the icon. If you can get your mouse there fast enough (maybe put it in the right place, sleep, then wake your Mac?) you might see the app name before it closes. Then you'll have a better idea what it is.
    You might also try the Activity Monitor application, which is in the /Applications/Utilities folder. It shows all the running processes, so you might be able to catch the app name before it closes.
    When you know what the application is called, you may decide it's not a problem at all. If it's still unclear, come back and post it, and maybe someone will be able to tell you what it is. Lots of applications use little "helper apps," and it's possible it could be something like that. It's best to know what it is, but it's probably harmless.
    G4 400 AGP   Mac OS X (10.4.2)  

  • Problem with JComboBox in a JPanel

    I have a JComboBox in a JPanel (with a gridbaglayout), and I add items to the combobox:
    String[] stateList={"AL",.....};
    JCombobox stateCB=new JComboBox(stateList);
    and when I run the application, the states appear in the box, but when I click on the box, there is no drop-down list!
    any ideas?

    Is the combobox Enabled if it is then after adding it to anything set it to true cause i poersonally tried out as u have given it it works and else if it does not show a list then use the setmodel function and set the model to DefaultComboBoxModel and then add the items using a for loop

  • Problem with JComboBox in a fixed JToolBar

    Hi,
    I've created a JComboBox in a JToolBar that contains all available fonts. When I click on the drop down arrow I only see the first font and a small part of the second. The JComboBox is dropped down in fact just as far as the border of the JToolbar. All the rest isn't visible to me; it seems that they are behind the other components of my JApplet. However, if I move the JToolBar from it's position (as it's a floatable component), there's no problem at all. So I'm wondering why I can't see everything when the JToolBar is docked.... Can anyone help me?
    Thanks in advance!!
    E_J

    it seems that they are behind the other components of my JApplet.Sounds like you are mixing AWT components with your Swing application. Make sure you are using JPanel, JButton ... and not Panel, Button....

Maybe you are looking for