Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

2 x JButton?!?

Empfohlene Antworten

Veröffentlicht

Hallo Leutz,

hab ma wieder ne Frage:

Un zwar hab ich einen JButton, der mit nem ActionListener z.B eine Hälfte einer SplitPane sichtbar macht. Wenn ich ein weiteres Mal auf den Button drücke, soll die Hälfte wieder verschwinden. Also hab ich mir das so gedacht:

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(ActionEvent e) {

jButton1_actionPerformed(e);

}

});

...und dann...

void jButton1_actionPerformed(ActionEvent e) {

if(bottomPane.isVisible() == false) {

bottomPane.setVisible(true);

}

else {

bottomPane.setVisible(false);

}

So, sieht einfach aus, ist es eigentlich auch. Ich kann mir nur nicht erklären, warum das ganze nur einmal funktioniert. Also drücke Button --> SplitPane da --> drücke Button --> SplitPane weg --> drücke Button --> nix tut sich mehr.

Kann mir jemand helfen?

Danke.

Hi!

Also auf Anhieb seh ich da keinen Fehler oder dergleichen..

Aber poste doch mal deinen kompletten Quellcode, vielleicht finden wir ja dann die Lösung deines Problems! Ist außerdem einfacher zu testen!

(Copy,Paste&Compile! :D:D:D)

Gruß

Azrael

Es geht noch ein kleines bisschen einfacher (deine if-Abfrage).

void jButton1_actionPerformed(ActionEvent e) {

bottomPane.setVisible( !bottomPane.isVisible() );

}

Danke, hat aber auch nix gebracht. Den ganzen Source kann/darf ich leider nicht

posten.

Vielleicht gehts ja gar nicht mit ActionPerformed sondern mit ItemStateChange oder

PropertyChange oder stateChanged?

Hm, muß mal nach nem anderen Lösungsweg suchen.

Also, leg ich das ganze auf ne JTable statt JSplitPane, gehts einwandfrei. Das liegt

folglich an der SplitPane. Nunja, da werd ich mal in den Bugreports suchen.

Hier die Lösung:

void jButton1_actionPerformed(ActionEvent e) {

if(bottomPane.isVisible())

bottomPane.setVisible(false);

else {

bottomPane.setVisible(true);

}

jSplitPane1.updateUI();

}

jSplitPane1.updateUI() --- durch Zufall drauf gestoßen. Hab mir ja gedacht, dass es

einfach sein muß.

Bis denne....

Anstatt:

Original geschrieben von GeneralChang

void jButton1_actionPerformed(ActionEvent e) {

if(bottomPane.isVisible())

bottomPane.setVisible(false);

else {

bottomPane.setVisible(true);

}

jSplitPane1.updateUI();

}

einfach

void jButton1_actionPerformed(ActionEvent e) {

	bottomPane.setVisible( !bottomPane.isVisible() );

	jSplitPane1.updateUI();

}

!

Ist wesentlich schöner und vor allem ohne "if"!!:D

Mach dir doch einfach mal ein paar System.out.println´s in deine if-Blocks, ob du überhaupt in die entsprechenden Blöcke kommst.

Snowghost

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.