On Mon, 3 Jul 2023 11:11:47 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:
>>> What if `JComboBox` uses a non-standard renderer which takes a property >>> from an object? Let's assume, `JComboBox` is populated with `Rectangle` >>> objects, a custom renderer is set which displays the value of the `bottom` >>> field in the combo box. Your code, if I understand it correctly, will >>> default to _full rectangle_ rather than what's really displayed. >>> >> You were right. At least in this case the current fix returns >> _full_rectangle_ dimension in a string form in stead of the text displayed >> in JComboBox. I had a doubt here if a custom renderer is used to populate >> the JComboBox, isn't it required to `override` the `toString` method to >> return useful information from user end? >> >> If not then I think it is required to look for alternate fix, probably to >> get the displayed text from JComboBox and set it as an accessibleName. >> >> >How does JTable handle this kind of situation? Or JList? >> >> I case of JTable and JList, the accessible context is of type JLabel which >> returns the accessibleName in string format. > >> > What if `JComboBox` uses a non-standard renderer which takes a property >> > from an object? Let's assume, `JComboBox` is populated with `Rectangle` >> > objects, a custom renderer is set which displays the value of the `bottom` >> > field in the combo box. Your code, if I understand it correctly, will >> > default to _full rectangle_ rather than what's really displayed. >> >> You were right. At least in this case the current fix returns >> _full_rectangle_ dimension in a string form instead of the text displayed in >> JComboBox. > > Thank you for confirming it. > >> I had a doubt here if a custom renderer is used to populate the JComboBox, >> isn't it required to `override` the `toString` method to return useful >> information from user end? > > No, it's not required to override the `toString` method if the programmer > doesn't use it. > >> If not then I think it is required to look for alternate fix, probably to >> get the displayed text from JComboBox and set it as an accessibleName. > > Could be… > > How would you get the text? It should be provided by a renderer… > >> > How does JTable handle this kind of situation? Or JList? >> >> I case of JTable and JList, the accessible context is of type JLabel which >> returns the accessibleName in string format. > > This doesn't really answer the question. Do `JTable` and `JList` correctly > display the magnified text when a custom renderer is used? In the case with > rectangle and a custom renderer? Do they still display text from `toString`? > > If neither `JTable` nor `JList` handle this situation, it's okay to go with > `toString` as you implemented. How does `JTable` handle the situation where an image is displayed? You can use SwingSet2 for testing: it displays colored text and images. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/14497#discussion_r1250725240