Trying to set a JLabel off of a JTable

Hi! I am trying to let a user select a row from a Jtable and have those highlighted values displayed below in another panel. Problem is that the gui never seems to refresh. Any ideas?
public class MainClass{
  public static void main( String[] args ){
    JFrame mainFrame = new JFrame( "Main Class" );
    MyTableModel tableModel = new MyTableModel();
    JTable table = new JTable( tableModel );
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    ListSelectionModel rowSM = table.getSelectionModel();
    rowSM.addListSelectionListener( new PanelModel() );
    JScrollPane tableScrollPane = new JScrollPane( table );
    tableScrollPane.setPreferredSize( new Dimension( 80, 80 ) );
    PanelView panelView = new PanelView();
    JScrollPane panelScrollPane = new JScrollPane( panelView );
    panelScrollPane.setPreferredSize( new Dimension(80, 80) );
    mainFrame.getContentPane().add( tableScrollPane, BorderLayout.NORTH );
    mainFrame.getContentPane().add( panelScrollPane, BorderLayout.SOUTH );
    mainFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    mainFrame.pack();
    mainFrame.setVisible( true );
public class PanelModel implements ListSelectionListener{
  private String anything;
  MyTableModel tableModel = new MyTableModel();
  public void valueChanged(ListSelectionEvent lse) {
    if (lse.getValueIsAdjusting()) return;
    ListSelectionModel lsm = (ListSelectionModel)lse.getSource();
    if (lsm.isSelectionEmpty()) {
      //no rows are selected
    } else {
      int selectedRow = lsm.getMinSelectionIndex();
      String rowValue = (String)tableModel.getValueAt(selectedRow, 0);
      this.populate( rowValue );
  public void populate(String something){
    this.setAnything(something);
    PanelView myPanelView = new PanelView();
    myPanelView.RowInfoField.setText(this.getAnything());
    myPanelView.updateUI();
  public String getAnything() {
    return this.anything;
  public void setAnything( String anything ) {
    this.anything = anything;
public class MyTableModel extends AbstractTableModel{
  private String[] columns = {"Column 1"};
  private String[][] rows = { {"Something"}, {"Anything"} };
  private static int selectedRow;
  public int getColumnCount(){
    return columns.length;
  public int getRowCount(){
    return rows.length;
  public int getSelectedRow(){
    return selectedRow;
  public Object getValueAt(int r, int c){
    if(rows[r] != null && columns[c] != null){
      return rows[r][c];
    return null;
public class PanelView  extends JPanel{
  MyTableModel tm;
  int rowSelected = 0;
  private String rowInfo;
  JLabel RowInfoField;
  JLabel RowInfoLabel;
  JPanel panelModel;
  public PanelView() {
    panelModel = new JPanel( new GridLayout() );
    tm = new MyTableModel();
    rowSelected = tm.getSelectedRow();
    rowInfo = (String)tm.getValueAt(rowSelected,0);
    JLabel RowInfoLabel = new JLabel( "RowInfo  " );
    RowInfoLabel.setForeground( Color.black );
    RowInfoField = new JLabel(rowInfo);
    RowInfoField.setFont( new Font( "Serif", 1, 11 ) );
    panelModel.add( RowInfoLabel );
    panelModel.add( RowInfoField );
    this.add( panelModel );
    this.setEnabled( true );
}

The problem is in the PanelModel.java line 24. Every time you create new PanelView but not add to the Frame. Following is a quick fix.
PanelModel.java
===================================================================
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
public class PanelModel implements ListSelectionListener{
private String anything;
MyTableModel tableModel = new MyTableModel();
public void valueChanged(ListSelectionEvent lse) {
if (lse.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)lse.getSource();
if (lsm.isSelectionEmpty()) {
//no rows are selected
} else {
int selectedRow = lsm.getMinSelectionIndex();
String rowValue = (String)tableModel.getValueAt(selectedRow, 0);
this.populate( rowValue );
public void populate(String something){
          System.out.println("something: " + something);
this.setAnything(something);
          MainClass.panelView.RowInfoField.setText(this.getAnything());
// PanelView myPanelView = new PanelView();
// myPanelView.RowInfoField.setText(this.getAnything());
// myPanelView.updateUI();
public String getAnything() {
return this.anything;
public void setAnything( String anything ) {
this.anything = anything;
===================================================================
MainClass.java
===================================================================
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
public class MainClass{
public static PanelView panelView;
public static void main( String[] args ){
JFrame mainFrame = new JFrame( "Main Class" );
MyTableModel tableModel = new MyTableModel();
JTable table = new JTable( tableModel );
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener( new PanelModel() );
JScrollPane tableScrollPane = new JScrollPane( table );
tableScrollPane.setPreferredSize( new Dimension( 80, 80 ) );
panelView = new PanelView();
JScrollPane panelScrollPane = new JScrollPane( panelView );
panelScrollPane.setPreferredSize( new Dimension(80, 80) );
mainFrame.getContentPane().add( tableScrollPane, BorderLayout.NORTH );
mainFrame.getContentPane().add( panelScrollPane, BorderLayout.SOUTH );
mainFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
mainFrame.pack();
mainFrame.setVisible( true );
===================================================================
MyTableModel.java
===================================================================
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.table.*;
public class MyTableModel extends AbstractTableModel{
private String[] columns = {"Column 1"};
private String[][] rows = { {"Something"}, {"Anything"} };
private static int selectedRow;
public int getColumnCount(){
return columns.length;
public int getRowCount(){
return rows.length;
public int getSelectedRow(){
return selectedRow;
public Object getValueAt(int r, int c){
if(rows[r] != null && columns[c] != null){
return rows[r][c];
return null;
===================================================================
PanelView.java
===================================================================
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.*;
public class PanelView extends JPanel{
MyTableModel tm;
int rowSelected = 0;
private String rowInfo;
JLabel RowInfoField;
JLabel RowInfoLabel;
JPanel panelModel;
public PanelView() {
panelModel = new JPanel( new GridLayout() );
tm = new MyTableModel();
rowSelected = tm.getSelectedRow();
rowInfo = (String)tm.getValueAt(rowSelected,0);
JLabel RowInfoLabel = new JLabel( "RowInfo " );
RowInfoLabel.setForeground( Color.black );
RowInfoField = new JLabel(rowInfo);
RowInfoField.setFont( new Font( "Serif", 1, 11 ) );
panelModel.add( RowInfoLabel );
panelModel.add( RowInfoField );
this.add( panelModel );
this.setEnabled( true );
===================================================================

Similar Messages

  • I tried to set up a new account but it has a master password and do not recall setting one how do I change that it will not let me turn it off without knowing the password I do not recall ever setting on. How do I clear the Master Password?

    I was trying to set up my mobile phone with Android with the Firefox App and my Netbook which I use the Firefox on and sync them but it came up that I have a Master Password but I do not recall setting one up and I have record of all my passwords that I keep in a secure place and I had trouble with a hacker who had accessed several of my accounts and I am now concerned that they may have also access this and we did not catch this one as we did the other accounts and stopped them from getting access. But that is not my concern any longer as that has been remedied the problem is how do I get the password unlocked or changed since I have no idea what it is? I tried to turn it off but it will not allow me to do that either without knowing it. Please advise as to what can be done so I can use this App on my Droid. Thanks. Deborah

    I was trying to set up my mobile phone with Android with the Firefox App and my Netbook which I use the Firefox on and sync them but it came up that I have a Master Password but I do not recall setting one up and I have record of all my passwords that I keep in a secure place and I had trouble with a hacker who had accessed several of my accounts and I am now concerned that they may have also access this and we did not catch this one as we did the other accounts and stopped them from getting access. But that is not my concern any longer as that has been remedied the problem is how do I get the password unlocked or changed since I have no idea what it is? I tried to turn it off but it will not allow me to do that either without knowing it. Please advise as to what can be done so I can use this App on my Droid. Thanks. Deborah

  • I got an iphone 3g off a friend of mine and i have tried to set it up and it wont activate it says it cannot do this at this time and the server is down help me please

    please help me please i got an iphone 3g off a friend of mine and when i have tried to set it up it says that (your iphonecould not be activated because the activation server is temporerally unavailerble. Try connecting ypur iphone to itunes to activate it, or try again in a few muinites. if this problem persists, contact apple support at apple.com/support) but it says the same when i connect it to itunes as well someone help me please

    Hello tom,
    I understand you are having issues activating an iPhone 3G. The following article addresses the exact error message you included:
    iPhone: Troubleshooting activation issues
    http://support.apple.com/kb/TS3424
    Resolution
    - Restart the iPhone.
    - Try another means of reaching the activation server and attempt to activate.
              - Try connecting to Wi-Fi if you're unable to activate using a cellular data connection.
              - Try connecting to iTunes if you're unable to activate using Wi-Fi.
    - Restore the iPhone.
    If you receive an alert message when you attempt to activate your iPhone, try to place the iPhone in recovery mode and perform a restore.
    Thanks,
    Matt M.

  • I am trying to set up iCloud but can't get to the iCloud on/off settings

    I an trying to set up iCloud but can't get to the iCloud on?off switch to turn on mail.
    thanks for your help

    www.apple.com/support/icloud

  • Hey I bought an iPhone off gumtree and everything was well. But then I tried to set it up and it asked for the apple if of the previous owner and so I asked him for it his Apple ID but refused to tell me so I can not use the phone. how do I fix this?

    Hey I bought an iPhone off gumtree and everything was well. But then I tried to set it up and it asked for the apple if of the previous owner and so I asked him for it his Apple ID but refused to tell me so I can not use the phone. how do I fix this?

    Contact them back and have them follow these instructions  Find My iPhone Activation Lock: Removing a device from a previous owner’s account - Apple Support

  • I am trying to set up my Apple TV to a Samsung TV and the TV is not recognizing it.  I rebooted, turned everything off, unplugged it, what am I doing wrong?

    I am trying to set up an Apple TV to a Samsung TV and the Samsung TV does not recognize it.  I tried unplugging everything and rebooting, but nothing is working.  What's the trick? thanks

    If it's 'going to regular programming' then you are not navigating to the right input. You need to use your Samsung remote to switch the input to whichever HDMI port the Apple TV is connected to, refer to your manual if unsure.
    To make sure it's secure means the cable has to be completely plugged in on both ends, if you can pull it out easily then that means it's loose.

  • My new iPod touch 4th gen is not working only showing apple icon! Been on charge for ages! And have tried to re set it turning off coming back to icon screen then not doing anything from there! Help!

    New iPod touch. Been working fine, needed charging so have charged it for ages. Only apple icon screen is appearing and nothing else! Have tried re setting still nothing! Help!

    - See:      
    iPod touch: Hardware troubleshooting
    - Try another cable. Some 5G iPods were shipped with Lightning cable that were either initially defective or failed after short use.
    - Try another charging source
    - Inspect the dock connector on the iPod for bent or missing contacts, foreign material, corroded contacts, broken, missing or cracked plastic.
    - Make an appointment at the Genius Bar of an Apple store.
      Apple Retail Store - Genius Bar 

  • I am trying to set up Sharing amongst several computers on my home network.  I have followed all the setup instructions but after completion Sharing does not appear in my iTunes window (on any of the computers I've set up).  There is no explanation why.

    I have been trying to set up Sharing between two computers on my network. I did this once and it worked.  However, when I try to set this up now the Sharing feature does not appear on the left side of the iTunes window (on either computer).  There is no explanation as to why not.  Is this a configuration problem, a network problem or what?   Can it be fixed?  I have tried turning sharing off and back on on both computers but to no avail.  What am I missing?  Thanks for any help you can provide.

    Hey innerev2003,
    Thanks for the question, and welcome to Apple Support Communities.
    If, while searching through your past purchases, items are unavailable to download and show a "Purchased" button, they are still on your computer. It may be best to search your iTunes library by clicking Music, then use the search bar at the top right.
    If you are completely sure the items are no longer in your library, try signing out of the iTunes Store, and then back in.
    iTunes 11 for Windows: Manage your iTunes Store account
    http://support.apple.com/kb/PH12507
    Thanks,
    Matt M.

  • I'm trying to set up my Ipod, but when I go to sign in with an apple ID it says 'Could not sign in: there was a problem connecting to the server'.

    I just bought a 3rd generation ipod touch. It was professionally refurbished. I'm trying to set it up, and everything seems to be working fine, until we get to the wifi. I live on campus and our wifi is username and password protected. I signed in and everything seemed to work fine, and in the top left hand corner I have all the bars for wifi. However, when I go to sign in with an apple ID it says 'Could no sign in: there was a problem connecting to the server'. I've tried turning it on and off again, tried signing on to our wifi again, but it all isn't working. What can I do?

    I also encountered the same problem. Try using a different email address or try signing in later.

  • I am trying to set up account aliases on icloud

    For the past month i have been trying to set up a new alias on icloud.  I originally had 3 aliases that came over from my .mac account days.  I then deleted one and had to wait seven days to create a new one.  Immediately after deleting it and logging off and back on to icloud it appeared the alias was gone.  When I went back out there 7 days later to create a new one the old supposedly deleted alias was there again.  So I deleted it again and had to start the whole wait process again.  This time it stayed deleted but when I went to select a new alias, instead of getting a prompt saying something to the affect of "that alias is already in use"  I got "Can not save this alias at this time" which lead me to believe that maybe the system didn't know my 7 days were up .  So I just tried another random alias and the system created that alias.  Because it wasn't so random as to render itself useless I decided to keep it and delete one of the other two and then of course wait 7 days. I checked back at the 3 day mark it was still gone.  Today is the 7 day mark and I just went out there and low and behold I magically have 3 aliases!  TWO of the same "random" aliases.  Oddly one of the random aliases has .me and .mac as the emails. Where as the rogue third alias of the same title only has the .me email.  Both contain all the same information with the only exception being the additional .mac email on one.  I decided to delete the magically appearing third alias today and now I'll have to wait 7 days to try to create another. What the ****?
    Can someone please tell me what is going on here?  And is there anyway to create an alias without waiting 7 days?  Is there a way to test to see if an alias is already in use?
    Anyone? Anyone?

    1. If you haven't tried this already, just delete the user account entirely, and then try setting it up again.
    2. To find the permissions file:
         a. hold down the option key
         b. go to the Go menu in the finder
         c. scroll down to Library and open it
         d. in Library, go to Containers/com.apple.mail/Data/Library/Preferences
         e. drag it to the trash and restart.
    3. if that doesn't work, go to Applications/Utilities/Keychain Access. In the Keychain Access menu, do Keychain First Aid, and repair.
    This should keep you busy for a while.

  • Trying to set up Airport Express with Ethernet Powerline adapters

    Hello,
    Having some problems trying to set up my Airport Express with Netgear ethernet powerline adapters.
    I want to set up as follows:
    Wireless Belkin router --- powerline <---> powerline --- airport express --- home stereo system
    The problem I have is that I can connect the airport x in client mode & wirelessly play music using airtunes (until the sound breaks up) but itunes does not find the airport x when connected via the powerlines.
    I have airport admin utility configured as follows:
    Airport tab:
    Wireless mode: create a wireless network
    Wireless network name: same as my wireless router SSID
    Allow this network to be extended: unticked
    radio mode: 802.11n (802.11b/g compatible)
    Channel: automatic
    Wireless Security: WPA/WPA2 personal (as per my router)
    Wireless Password: as per my router
    Verify Password: as per my router
    Internet tab:
    Connect using: ethernet
    Connection sharing: off (bridge mode)
    Music tab:
    Enable Air Tunes ticket
    no password set
    In iTunes, I have home sharing on & share entire library selected with no password set.
    Using OS 10.6.5 & Airport Express 7.5.2
    I can ping the IP address of the airport express when connected via the powerlines but cannot select the speakers in iTunes (they are greyed out).
    Any assistance would be appreciated....
    Thanks

    Hi,
    Thanks for the quick response...
    As suggested, I connected up the Airport X to the Belkin and plugged in a pair of headphones. It didn't work, still could not select the Airport X as speakers.
    Dug out my old Netgear DG834G and connected that up in place of the Belkin - it worked. Next connected in the Netgear powerlines and it still worked.
    So, the problem is the relatively new Belkin F7D4401 router.
    Looks like I will have to find an alternative 802.11n...
    Thanks for your help.
    Regards
    Simon

  • TS3682 I'm trying to set up my new iPhone 5s with my iCloud account.  I backed up my iPhone 4s before I started.  I got an error message about backing up from my mac and my mac had installed an update.  However my new iPhone 5s looks frozen??

    I'm trying to set up my new iphone 5s.  I've backed up my icloud for my 4s to my mac.  When I've tried to download from my icloud to my 5S i got an error message and my mac has updated itunes (I think).  My new 5s is just sitting with the apple logo and a bar underneath which has moved about 10% but nothing for about 20 mins.  I can't turn the 5s off?  What do I do?

    Problem resoled -  it sorted itself out!!  Thought I'd broken it before I'd even used it.

  • I keep trying to set up a new Apple ID but apparently my card info is not working. how do i fix this? "contact ituunes support to complete this transaction"

    i keep trying to set up a new Apple ID but apparently my card info is not working. how do i fix this? "contact ituunes support to complete this transaction"

    If the problem persists, you'll probably have to make another apple id, it wont take off any games or music or apps or anything you've bought it will all stay there, i have two apple id's and i don't have a problem with anything.

  • Unknown error when trying to set up aol mail

    AOL just stopped working as of 10am today!  I sent mails this morning and now I cannot get AOL to work.  I deleted the account and tried to set up AOL Mail again and I keep getting an "Unknown Error" message!  HELP......

    Hey there jsmugs,
    It sounds like your AOL account is not working in your account, and you also cannot set it back up. I recommend the troubleshooting from the article named:
    iOS: Troubleshooting Mail
    http://support.apple.com/kb/ts3899
    Tap Safari and attempt to load a webpage (try any webpage). If you can load a webpage, then your device has Internet access. If you are unable to load a webpage, follow these troubleshooting steps.Try to use an alternate Internet connection if available:
    Try a different Wi-Fi connection
    If your iOS device has an active cellular data plan, tap Settings > Wi-Fi and turn off Wi-Fi.
    If the affected email account is provided by your Internet provider, see if your issue is resolved while connected to your home Wi-Fi network.*
    Log in to your email provider's website to ensure that the account is active and the password is correct.
    Restart your iOS device.
    Delete the affected email account from your device.
    Tap Settings > Mail, Contacts, Calendars.
    Choose the affected email account, then tap Delete Account.
    Add your account again.
    Thank you for using Apple Support Communities.
    All the best,
    Sterling

  • Trying to set up 2 Airport Extremes to replace my old 802.11g pair.

    Hello...
    I am trying to set up my extended Airport Extreme network with new Extremes to replace my older 802.11g pair.
    Here is the situation: I have Cable 'net access that comes into my studio. It is then wired to the "Studio Extreme" into the WAN port. Then there is an Ethernet wire from the Ethernet port to a hub, which is wired through the wall to hub 2, that goes apx 500ft via CAT6 to my house. Then there is another hub that wires all the Ethernet ports in the walls of the house. Out of one port is AirPort Extreme # 2.
    The Problem:
    My old AirportExtreme #2 works fine. The new one won't play nice.
    The Studio Airport is set to: Create A Wireless Network with WPA2 Personal security. It is happy with a green light.
    The New AirportExtreme 802.11n is set to: Extend a wireless network with WPA2 Personal Security. It says Connect using: Wireless network.
    I have tried to set it up with the Ethernet cable going into the WAN port, and the Ethernet port. When it is in the WAN port, it says "nothing is in the WAN port". When it is in the Ethernet port, it says It can't find the network. I have tried unplugging everything and turning it back on, in reverse order etc. When I bring the New Extreme #2 to the studio, it plays nice, but I suspect it is working wirelessly with the Studio Extreme. (?). 
    I have tried to set it to "Create a wireless network" as I have seen suggested in some forums. Still doesn't make it happy.
    I also tried to let the software " replace the old Airport with the new Airport" . that didn't work either.
    The Old Extreme 802.11g still works and is happy also. Its cable is plugged into the Ethernet port and it transmits throughout the house.
    I am going nuts trying to get this to work! Why does the old one work and not  the new one?
    HELP!!!!
    Thank you!

    You got ahead of things here (and chose the wrong settings), but we can correct things.
    Reset the AirPort Extreme again, please.
    Then open AirPort Utility, select the AirPort Extreme, and click Manual Setup.
    Click the Base Station tab under the row if icons to name the AirPort Extreme, assign a device password and adjust Time Zone settings.
    Now, click the Wireless tab next to the Base Station tab and adjust settings as follows:
    Wireless Mode = Create a wireless network  (Extend is used only if you connect using wireless...and you are connecting using Ethernet)
    Wireless Network = Same name as your "main" AirPort Extreme
    Enter a check mark next to Allow this network to be extended
    Radio Mode = Automatic
    Radio Channel = Automatic
    Wireless Security = Same setting as the "main" AirPort Extreme
    Wireless Password = Same password as the "main" AirPort Extreme
    Confirm Password
    Click the Internet icon, then click the Internet Connection tab
    Connect Using = Ethernet
    Connection Sharing = Off (Bridge Mode)
    Click Update and wait 25-30 seconds for a green light
    Very Important......Power off the entire network and wait a minute or two
    Power up the modem first and let it run a minute by itself
    Power up the "main" AirPort Extreme the same way
    Power up the "remote" AirPort Extreme the same way
    Continue powering up devices one at a time until everything is powered up
    The network should now be functioning correctly.

Maybe you are looking for

  • How to activate the Vertival Scroll Bar to Table control

    Hi All, I Have created a Module pool table control(Wizard) with Input control,where user can enter the values in the screen. In my screen 15 lines are visible,once i enter all 15 rows,vertical scroll bar is active,but rest of all lines are in deactiv

  • Batch split in inbound delivery according to Handling Units in Idoc

    Hi everyone, the Idoc with different HU's segments E1EDL37 (all the same batch no.), causes different items in the inbound delivery. But we need only one item, because it's the same batch no.! Where can I customize this? Thx in advance! Thomas

  • Nano 3rd GEN & Apple Universal Dock

    Hi! I've just bought a nano 3rd GEN and a Apple Universal Dock. I've a probleme with the compatibility of these two devices. When I'm connecting the nano with the Universal Dock, there is only one channel (the right channel) whitch works. I've try a

  • Add header to splitted video in j2me

    hello , im developing a application in which i want to download a large  file in to chunks n play them chunck by chunk but im able to play first file only remaining files are not getting played i think its because of missing header file in remaining

  • Time Machine Failing Over and Over

    So I am backing up my EX HD with Time Machine for the first time and it keep failing. It stops between 3 gb and about 20gb (I have 180 total). Keeps giving the error "The backup was not performed because an error occurred while copying files to the b