• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problems with SwitchButton NSButtonCells in NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with SwitchButton NSButtonCells in NSTableView


  • Subject: Problems with SwitchButton NSButtonCells in NSTableView
  • From: Ian Crew <email@hidden>
  • Date: Mon, 25 Mar 2002 17:09:23 -0800

Greetings:

I have an NSTableView that contains a bunch of NSButtonCells, set to be SwitchButtons. Everything seems to be working perfectly, with the following two exceptions:

1) How do I implement tableViewSetObjectValueForLocation to pick up a click in one of the SwitchBoxes correctly? (The implementation in the code below doesn't work properly--it changes the state whenever the user clicks anywhere in that cell as opposed to just on the button itself.)

2) When I click in one of the rows of the NSTableView, the title of the SwitchButton in that row is very briefly set to the value of the Switchbutton in the row I clicked on last, and then switches back to what it's supposed to be. Any idea why? (If it helps, my code appended at the bottom....)

Thanks!

Ian

-----------------------------------------------------------------

public class MyDataSource extends NSObject {
static final int MAXPRODUCTS = 4;
private boolean initialized = false;
MultiLauncherProduct products [];
//initialize the products array (will probably be done by an external function later)
private void initialize() {
System.out.println("Initializing");
initialized = true;
products = new MultiLauncherProduct[MAXPRODUCTS];
//products[0] = new MultiLauncherProduct("Netscape", false);
products[0] = new MultiLauncherProduct();
products[1] = new MultiLauncherProduct();
products[2] = new MultiLauncherProduct();
products[3] = new MultiLauncherProduct();
products[0].setName("Netscape");
products[1].setName("Eudora");
products[2].setName("Fetch");
products[3].setName("Norton AntiVirus");
products[0].setSelected(false);
products[1].setSelected(true);
products[2].setSelected(false);
products[3].setSelected(true);
}
public int numberOfRowsInTableView(NSTableView aTableView) {
return MAXPRODUCTS;
}

public Object tableViewObjectValueForLocation( NSTableView aTableView, NSTableColumn aTableColumn, int rowIndex) {
if (!initialized) initialize();
NSButtonCell theButton = new NSButtonCell();

if (aTableColumn.identifier().equals("Product")) {
theButton.setButtonType(theButton.SwitchButton);
System.out.println("--------");
System.out.println(theButton.title());
theButton.setTitle(products[rowIndex].getName());
System.out.println(theButton.title());
if (products[rowIndex].isSelected()) {
theButton.setState(1);
} else {
theButton.setState(0);
}
} else if (aTableColumn.identifier().equals("Help")){
theButton.setButtonType(theButton.MomentaryLight);
theButton.setBezelStyle(theButton.RoundedBezelStyle);
theButton.setTitle("?");
}
aTableColumn.setDataCell(theButton);
return theButton;
}

public void tableViewSetObjectValueForLocation( NSTableView aTableView, Object anObject, NSTableColumn aTableColumn, int rowIndex) {
if (aTableColumn.identifier().equals("Product")) {
if (products[rowIndex].isSelected()) {
products[rowIndex].setSelected(false);
} else {
products[rowIndex].setSelected(true);
}
}
return;
}
}
--
_____________________________________________________________________________
| "Dance to it, Sing to it, Love, Cry, Remember | Ian Crew |
| when, Imagine if, Wonder Why" -Anonymous | email@hidden |
|_______________________________________________|_____________________________|
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Prev by Date: Re: Apple and Developers (was lots of different subjects) (rekindling the fire)
  • Next by Date: Re: Apple and Developers (was lots of different subjects) (rekindling the fire)
  • Previous by thread: Re: Working with Audio
  • Next by thread: Debugging/Running Problems Solved
  • Index(es):
    • Date
    • Thread