ERLEDIGT
NEIN
NEIN
ANTWORTEN
2
2
ZUGRIFFE
2221
2221
EMPFEHLEN
-
Hi
Ich versuch gerade ein Bild als anklickbaren Button zu erstellen und dieser soll nur sichtbar werden wenn ich mit der Maus drüber fahre. Bin mir aber nicht sicher ob das zu machen geht?
Wenn da jemand ne Lösung hätte wäre ich da sehr dankbar!!
(Brauch das für ein Projekt in meiner Ausbildung)
mfg
-
Hallo,
schau mal hier:
Code java:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
import java.awt.BorderLayout; import java.awt.Insets; import java.awt.Rectangle; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.image.BufferedImage; import javax.swing.*; import javax.swing.table.AbstractTableModel; public class ScrollExample extends JFrame implements MouseListener { private BufferedImage buf = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); private ImageIcon img1 = new ImageIcon("b1.jpg"); private ImageIcon img2 = new ImageIcon(buf); private JButton b1 = new JButton(img2); private JButton b2 = new JButton(img2); private JButton b3 = new JButton(img2); private JButton b4 = new JButton(img2); private JTable t = new JTable(new QuadratTableModelSimple()); private JScrollPane sp = new JScrollPane(t); public ScrollExample() { super("ScrollExample"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setAlwaysOnTop(true); this.setLocationByPlatform(true); t.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); b1.addMouseListener(this); b2.addMouseListener(this); b3.addMouseListener(this); b4.addMouseListener(this); b1.setName("North"); b2.setName("East"); b3.setName("South"); b4.setName("West"); this.modificateButton(b1); this.modificateButton(b2); this.modificateButton(b3); this.modificateButton(b4); this.add(b1, BorderLayout.NORTH); this.add(b2, BorderLayout.EAST); this.add(b3, BorderLayout.SOUTH); this.add(b4, BorderLayout.WEST); this.add(sp, BorderLayout.CENTER); this.pack(); this.setVisible(true); } public static void main(String[] args) { new ScrollExample(); } public void showButton(JButton b) { b.setIcon(img1); b.setBorderPainted(true); } public void hideButton(JButton b) { b.setBorderPainted(false); b.setIcon(img2); } public void modificateButton(JButton b) { b.setContentAreaFilled(false); b.setFocusPainted(false); b.setBorderPainted(false); b.setMargin(new Insets(0, 0, 0, 0)); b.setIcon(img2); } public void mouseClicked(MouseEvent e) { } public void mousePressed(MouseEvent e) { Rectangle r = t.getVisibleRect(); switch (((JButton) e.getComponent()).getName().charAt(0)) { case 'N': r.translate(0, -5); break; case 'E': r.translate(5, 0); break; case 'S': r.translate(0, 5); break; case 'W': r.translate(-5, 0); break; } t.scrollRectToVisible(r); } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { this.showButton((JButton) e.getComponent()); } public void mouseExited(MouseEvent e) { this.hideButton((JButton) e.getComponent()); } class QuadratTableModelSimple extends AbstractTableModel { public int getRowCount() { return 30; } public int getColumnCount() { return 20; } public Object getValueAt(int row, int col) { if (col == 0) return "" + row; else if (col == 1) return "" + (row * row); else return "" + (row * row * row); } public String getColumnName(int column) { return "Spalte" + column; } } }
Vg Erdal
-
Vielen Dank hat mir echt weitergeholfen!
mfg
Ähnliche Themen
-
Bild aus button + 2 bild wenn zeiger drauf ist
Von Viper2009 im Forum JavaAntworten: 10Letzter Beitrag: 07.12.07, 23:09 -
Button mit Bild
Von xloouch im Forum HTML & XHTMLAntworten: 1Letzter Beitrag: 24.11.07, 15:20 -
Bild als Button
Von luukvh im Forum HTML & XHTMLAntworten: 3Letzter Beitrag: 19.06.07, 23:14 -
Bild als Button
Von Dipsi im Forum VisualStudio & MFCAntworten: 3Letzter Beitrag: 12.11.05, 20:37 -
Bild als Button
Von warlike im Forum JavaAntworten: 2Letzter Beitrag: 12.07.05, 10:14





Zitieren
Login





