Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.java > #12854

Re: Java/NetBeans: Verwaltung von RadioButtons in einer ArrayList

From Patrick Roemer <sangamon@netcologne.de>
Newsgroups de.comp.lang.java
Subject Re: Java/NetBeans: Verwaltung von RadioButtons in einer ArrayList
Date 2015-10-25 18:34 +0100
Organization news.netcologne.de
Message-ID <n0j3q9$han$1@newsreader4.netcologne.de> (permalink)
References <phcm2bde5n30n847r75qdjjvh60jiik2ae@4ax.com> <n0g1cj$fpi$1@newsreader4.netcologne.de> <he2p2btvcav0m33c18fkr3051n8gbji4k6@4ax.com>

Show all headers | View raw


Responding to Rainer:
> On Sat, 24 Oct 2015 15:34:11 +0200, Patrick Roemer
> <sangamon@netcologne.de> wrote:
>>int boxCount = ...;
>>for(int idx = 0; idx < boxCount; boxCount++) {
>>  boxlist.add(new JCheckBox());
>>}

Natürlich "idx++", nicht "boxCount++". m(

> Und wie kann man Events systematisch abfragen, d. h. statt
> 
> private void chkEinsActionPerformed(java.awt.event.ActionEvent evt) {
>         ...
> }                                           
> 
> private void chkZweiActionPerformed(java.awt.event.ActionEvent evt) {
>         ...
> }     
> 
> usw. ....
> 
> in einer Schleife abfragen, ob irgendeines der Kontrollkästchen
> geändert wurde, um dann Aktionen auszuführen?

Ganz naiv z.B. indem man anhand des Index der Checkbox die passende
Reaktion auswählt.

<snip>
private static void boxChanged(int boxIdx, boolean state) {
  System.out.println("Box #" + boxIdx + " switched to " + state);
}

for(int idx = 0; idx < numBoxes; idx++) {
  JCheckBox box = new JCheckBox();
  int curIdx = idx;
  box.addActionListener(ev -> boxChanged(curIdx, box.isSelected()));
  boxes.add(box);
}
</snip>

In der JTable-Variante würde das über TableModel#setValueAt() laufen.

Es kommt halt drauf an, was für ein Verhalten man eigentlich modellieren
möchte. Was soll diese "große Zahl" von Checkboxes denn darstellen, und
was wären die entsprechenden "Aktionen"?

Viele Grüße,
Patrick

Back to de.comp.lang.java | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Java/NetBeans: Verwaltung von RadioButtons in einer ArrayList Rainer <Rainer.Poop@ObjectMail.com> - 2015-10-24 09:28 +0200
  Re: Java/NetBeans: Verwaltung von RadioButtons in einer ArrayList Patrick Roemer <sangamon@netcologne.de> - 2015-10-24 15:34 +0200
    Re: Java/NetBeans: Verwaltung von RadioButtons in einer ArrayList Rainer <Rainer.Poop@ObjectMail.com> - 2015-10-25 08:54 +0100
      Re: Java/NetBeans: Verwaltung von RadioButtons in einer ArrayList Patrick Roemer <sangamon@netcologne.de> - 2015-10-25 18:34 +0100
      Re: Java/NetBeans: Verwaltung von RadioButtons in einer ArrayList Marco Bakera <pintman@bakera.de> - 2015-10-26 14:02 +0100

csiph-web