ERLEDIGT
NEIN
NEIN
ANTWORTEN
6
6
ZUGRIFFE
1007
1007
EMPFEHLEN
-
Hallo liebes forum,
ich versuch so etwas wie ein Formular zu erstellen,jedoch bekomme ich das nicht richtig hin.
Ich habe dafür ein code geschrieben,wenn ihr dies mal anschauen könnt würde ich mich sehr freuen.
Danke
Code :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
// Fig. 25.21: GridBagFrame.java // Demonstrating GridBagLayout. import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Component; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; public class GridBagFrame extends JFrame { private GridBagLayout layout; // layout of this frame private GridBagConstraints constraints; // constraints of this layout // set up GUI public GridBagFrame() { super( "GridBagLayout" ); layout = new GridBagLayout(); setLayout( layout ); // set frame layout constraints = new GridBagConstraints(); // instantiate constraints // create GUI components // JTextArea textArea1 = new JTextArea( "TextArea1", 5, 10 ); JLabel DvdName = new JLabel("DVD Name"); JLabel DvdType = new JLabel("DVD Type"); JLabel DvdPrice = new JLabel("DVD Price"); JTextField textField = new JTextField( "" ); JTextField textField2 = new JTextField( "" ); JTextField textField3 = new JTextField( "" ); JButton button1 = new JButton("Add to Database"); JButton button2 = new JButton("Cancel"); constraints.fill = GridBagConstraints.BOTH; constraints.gridx = 3; // x-Position constraints.gridy = 1; // y-Position addComponent( DvdName, 0, 0, 1, 1); constraints.fill = GridBagConstraints.BOTH; constraints.gridx = 3; // x-Position constraints.gridy = 1; // y-Position addComponent(DvdPrice, 1, 0, 2, 1); constraints.fill = GridBagConstraints.BOTH; constraints.gridx = 3; // x-Position constraints.gridy = 1; // y-Position addComponent(DvdType, 2, 0, 3, 1); constraints.fill = GridBagConstraints.BOTH; constraints.gridx = 3; // x-Position constraints.gridy = 1; // y-Position constraints.gridwidth = 4; // Breite constraints.gridheight = 1; addComponent(textField, 0, 1, 1, 2); constraints.fill = GridBagConstraints.HORIZONTAL; addComponent(button1, 5, 3, 2, 1); constraints.fill = GridBagConstraints.HORIZONTAL; addComponent(button2, 5, 5, 3, 1); } // method to set constraints on private void addComponent( Component component, int row, int column, int width, int height ) { constraints.gridx = column; // set gridx constraints.gridy = row; // set gridy constraints.gridwidth = width; // set gridwidth constraints.gridheight = height; // set gridheight layout.setConstraints( component, constraints ); // set constraints add( component ); // add component } }
-
01.12.10 07:47 #2
Moin,
vlt. solltest Du mal zusätzlich erklären, was genau denn nicht Deiner Erwartung entspricht resp. wo das Problem ist !
gruß
KlausEs ist noch kein Meister vom Himmel gefallen - sonst hätte man schon längst seine Leiche gefunden !!
Falls ich helfen konnte, wäre eine Bewertung oder ein Danke nett ;-)
-------------------------------------------------------------------------------------------------
Ich beantworte keine Fragen per PN !!
Stellt Eure Fragen im Forum - dann haben alle etwas davon !!
-
also ein Label untereinander ordnen. hm ich würde wohl eine JList erstellen und diese durch einen Renderer laufen lassen. ( dazu lässt sich bestimmt was google
)
aber wie vfl_freak schon sagte, wäre eine genauere angabe deiner Wünsche schon besser
Auch aus Steinen, die einem in den Weg gelegt werden, kann man Schönes bauen.
Goethe
-
Mit den GridBagLayout muesste sich doch alles so anordnen lassen wie du willst? Dort teilt man doch alles in Zeilen/Spalten ein.
Aber hellsehen kann hier noch keiner
Waere super wenn ihr euren Code in dieser Form einfuegt:
[JAVA]System.out.println("Test :)");[/JAVA]
wird zu:
Tabs sind uebrigens keine Feinde :)Code java:1
System.out.println("Test :)");
Der "Erledigt Button" beisst net :) Und der "Danke Button" ist auch nicht nur zur zierde
Danke :D
-
09.12.10 13:18 #5
- Registriert seit
- Dec 2010
- Beiträge
- 2
Ich wuerde das mit dem Form - Layout von JGoodies machen.
Ist meiner Meinung nach einfach als GridBagLayout:
siehe http://www.jgoodies.com/freeware/forms/index.html
-
Wie oben schon beschrieben würde sich das GridBagLayout am ehesten anbieden:
Label1:
gridX:0; gridY:0; gridWidth:1; gridHeight:1;
Label2:
gridX:0; gridY:1; gridWidth:1; gridHeight:1;
Textfield:
gridX:1; gridY:0; gridWidth1; gridHeight:2;
Diese Anordnung könnte natürlich noch ein bisschen eckig ausschauen aber wenn man ein bisschen mit den breiten herumspielt sollte man etwas schönes hinbekommen.
-
Hi,
ich persönlich arbeite sehr gerne mit dem BoxenLayout. Hier kann man einfach einer Box entweder eine horizontale oder vertikale Ausrichtung mitgeben, welche die Elemete dann entsprechend platziert.
Wenn man drei, vier solcher Boxen ineinander verschatelt, kann man leicht die gewünschte Optik erreichen ohne sich dabei um verschiedene Parameter zu kümmern.
Wenn es aber komplexer werden sollte, geht es mit dem GridBagLayout ebenso ganz gut (wie Tsunamii schon beschrieben hat)
Gruß Marc
Ähnliche Themen
-
Kann Cookie nicht setzten
Von Ninjasturm im Forum PHPAntworten: 11Letzter Beitrag: 31.07.10, 01:19 -
Input Textfeld wo richtig setzten!!
Von aherzog im Forum PHPAntworten: 5Letzter Beitrag: 30.06.08, 22:16 -
IE6 Scriptaculous Builder-> Kann kein Style setzten
Von C3000 im Forum Javascript & AjaxAntworten: 0Letzter Beitrag: 30.05.07, 14:40 -
Rechnen mit eingabe in Label oder Textfeld
Von aneril im Forum Visual Basic 6.0Antworten: 6Letzter Beitrag: 12.06.03, 16:46 -
Textdatei oder Textfeld ordnen/sortieren....
Von [K-DOG] im Forum Visual Basic 6.0Antworten: 9Letzter Beitrag: 07.01.02, 00:05





Zitieren
Login





