Je souhaite actuellement construire un type de mise en page pour JPanels. J'ai découvert qu'il existe une TableLayout pour Java mais je ne sais pas comment l'importer. D'un autre côté, j'ai découvert qu'il y a un GridBagLayOut qui peut également construire une table comme layout.Mais cela semble plus compliqué. Aucun conseil.Java TableLayout
Répondre
Voici un SSCCE d'utiliser un TableLayout, (Introduction to TableLayout)
import javax.swing.JButton;
import javax.swing.JFrame;
import layout.TableLayout;
public class TestTableLayout {
public static void main(String args[]) {
JFrame frame = new JFrame("Example of TableLayout");
frame.setSize(450, 450);
double size[][] = {{10, 75, 75, 75, 75, 75, 10}, // Columns
{10, 75, 75, 75, 75, 75, 10}}; // Rows
frame.setLayout(new TableLayout(size));
String label[] = {"(1,1)", "(1,5)", "(1,3)", "(5,3)", "(3,3)"};
JButton button[] = new JButton[label.length];
for (int i = 0; i < label.length; i++) {
button[i] = new JButton(label[i]);
}
frame.add(button[0], "1, 1");
frame.add(button[1], "1, 5");
frame.add(button[2], "1, 3");
frame.add(button[3], "5, 3");
frame.add(button[4], "3, 3");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Le pot requis pour le TableLayout peut être téléchargé à partir here
ont également un coup d'oeil: A Visual Guide to Layout Managers, Dans le cas.
Si vous optez pour GridBagLayout, un coup d'oeil à: How to Use GridBagLayout
Merci beaucoup pour votre temps et vos efforts. J'apprécie beaucoup. Il m'a aidé beaucoup –
@TheJAVANoob Welcome..Happy codage! :) – COD3BOY
- 1. Android ImageButton dans TableLayout
- 2. Actualiser tableLayout
- 3. Android TableLayout
- 4. TableRow dynamique dans TableLayout
- 5. Aide à la création de TableLayout dans l'activité .java
- 6. Centrer les lignes TableLayout en utilisant le code Java
- 7. ListViews inside TableLayout
- 8. Fond de TableLayout de sdcard
- 9. Dimensionnement de colonnes TableLayout
- 10. Android - TableLayout à ExpandableListView
- 11. L'affichage s'additionne avec TABLELAYOUT
- 12. Android TableLayout par programmation
- 13. Problème Android Tablelayout!
- 14. Lazy Images dans TableLayout
- 15. Espace supplémentaire dans TableLayout
- 16. Problème lié à TableLayout
- 17. TableLayout au sein HorizontalScrollView
- 18. Faites défiler dans TableLayout
- 19. GridView vs. TableLayout | Android
- 20. TableLayout avec pagination
- 21. Stretching TableLayout intérieur ScrollView
- 22. Android - Table TableLayout
- 23. Android TableLayout group dynamicButtons
- 24. Onglets Android avec TableLayout
- 25. Android TableLayout est redimensionnée
- 26. Android TableLayout wrap contenu
- 27. ShapeDrawable et TableLayout
- 28. Android TableLayout Directeur
- 29. Spanning colonnes avec TableLayout
- 30. TableLayout Orientation problème
Cela ne suffit me semble pas spécifique de rester une question ouverte SO ... pour répondre à votre question, persévérer 'GridBagLayout "- ce n'est pas trop compliqué une fois que tu l'auras fait. –
Eh bien, j'ai fait quelques recherches sur la façon de construire une table en Java. Et je suis tombé sur TableLayout et GridBagLayout. TableLayout semble le chemin à parcourir, mais je ne pouvais pas vraiment le faire fonctionner. –
Quelle est votre question? GridBagLayout devrait faire le travail parfaitement pour autant que je comprends. –