OVH Cloud OVH Cloud

deux JToolBar hor, vert

12 réponses
Avatar
yvon.thoravalNO-SPAM
Bonjour,

j'essaie d'avoir deux JToolbar, l'un horizontal "toolBarTables"
PAGE_START, l'autre vertical "toolBarManage" EAST :

add(toolBarTables, BorderLayout.PAGE_START);
add(scrollPane, BorderLayout.CENTER);
add(toolBarManage, BorderLayout.EAST);


mais le résultat me donne les deux JToolBar en une seule et en
BorderLayout.EAST...

y-a t'il un moyen d'en avoir deux ainsi ?


--
yt

10 réponses

1 2
Avatar
Philippe
Yvon Thoraval wrote:
Bonjour,

j'essaie d'avoir deux JToolbar, l'un horizontal "toolBarTables"
PAGE_START, l'autre vertical "toolBarManage" EAST :

add(toolBarTables, BorderLayout.PAGE_START);
add(scrollPane, BorderLayout.CENTER);
add(toolBarManage, BorderLayout.EAST);


mais le résultat me donne les deux JToolBar en une seule et en
BorderLayout.EAST...

y-a t'il un moyen d'en avoir deux ainsi ?


Ouai parceque je l'ai déjà fait et comme toi en plus.
(à l'exception du NORTH au lieu de PAGE_START)

Essaies de poster un code qui marche comme tu dis,
on pourra essayer de voir...

--
Philippe

Avatar
Mouloud Samadi
Tiré du javadoc jdk 1.4:

Mixing both absolute and relative positioning constants can lead to
unpredicable results. If you use both types, the relative constants will
take precedence. For example, if you add components using both the NORTH and
PAGE_START constants in a container whose orientation is LEFT_TO_RIGHT, only
the PAGE_START will be layed out.

Bonne chance

"Philippe" wrote in message
news:4152ab52$0$7190$
Yvon Thoraval wrote:
Bonjour,

j'essaie d'avoir deux JToolbar, l'un horizontal "toolBarTables"
PAGE_START, l'autre vertical "toolBarManage" EAST :

add(toolBarTables, BorderLayout.PAGE_START);
add(scrollPane, BorderLayout.CENTER);
add(toolBarManage, BorderLayout.EAST);


mais le résultat me donne les deux JToolBar en une seule et en
BorderLayout.EAST...

y-a t'il un moyen d'en avoir deux ainsi ?


Ouai parceque je l'ai déjà fait et comme toi en plus.
(à l'exception du NORTH au lieu de PAGE_START)

Essaies de poster un code qui marche comme tu dis,
on pourra essayer de voir...

--
Philippe



Avatar
yvon.thoravalNO-SPAM
Philippe wrote:

Ouai parceque je l'ai déjà fait et comme toi en plus.
(à l'exception du NORTH au lieu de PAGE_START)

Essaies de poster un code qui marche comme tu dis,
on pourra essayer de voir...


J'ai progressé, j'arrive à en mettre deux, mais seulement quand tout est
dans la même classe, avant j'avais une erreur vraiment bête, je
n'appellais pas le bon constructeur.

Maintenant j'ai créé deux classes :

public class ToolBarTables extends JToolBar implements ActionListener {
...

public JToolBar ToolBarTables() {

//Create the toolbar.
JToolBar toolBar = new JToolBar("Still draggable");
addButtons(toolBar);
toolBar.setFloatable(true);
toolBar.setRollover(true);

System.out.println("ToolBarTables() builded");

return toolBar;
}

...
}

idem pour public class ToolBarManage ...

et je fais un TestToolbar :

*
* placer les images dans [src/]yt/ui/images
*/

package yt.tests;

import java.awt.Dimension;

import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JTextField;

import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JPanel;

import java.net.URL;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import yt.ui.ToolBarTables;
import yt.ui.ToolBarManage;

public class TestToolBar {
protected JTextArea textArea;
protected String newline = "n";

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void TestToolBar() {
//super(new BorderLayout());
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());

//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.
JFrame frame = new JFrame("ToolBar");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the two toolbars.
JToolBar toolBarTables = new ToolBarTables();
JToolBar toolBarManage = new ToolBarManage();

//Create the text area used for output. Request
//enough space for 5 rows and 30 columns.
JTextArea textArea = new JTextArea(5, 30);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);

//Lay out the main panel.
contentPane.setPreferredSize(new Dimension(450, 350));
contentPane.add(toolBarTables, BorderLayout.PAGE_START);
contentPane.add(scrollPane, BorderLayout.CENTER);
contentPane.add(toolBarManage, BorderLayout.EAST);

contentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(contentPane);

//Display the window.
frame.pack();
frame.setVisible(true);
}

protected void displayResult(String actionDescription) {
textArea.append(actionDescription + newline);
textArea.setCaretPosition(textArea.getDocument().getLength());
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
TestToolBar();
}
});
}
}

Mais, aucune des deux ToolBar[Manage|Tables] n'apparaît...
il y a juste le grisé de "contentPane.add(toolBarManage,
BorderLayout.EAST);" qui apparaît.


j'ai donc mis un System.out.println dans les constructeurs, rien ne sort
à la console, cela signifie que les constructeurs ne sont pas appelés
???

je ne pige pas comment les JToolBar sont retournés à TestToolBar...

l'idée serait d'avoir qu'une seule class ToolBar et de l'appeler deux
fois
--
yt

Avatar
yvon.thoravalNO-SPAM
Philippe wrote:

Essaies de poster un code qui marche comme tu dis,
on pourra essayer de voir...


Vite fait, avant d'aller béqueter, j'explique ce que je veux faire :

|-----------------------------------------------------|
| ToolBarTables |
|-----------------------------------------------------|
| | |
| | |
| | T |
| | o |
| | o |
| | l |
| | B |
| JTable [n] | a |
| | r |
| | M |
| | a |
| | n |
| | g |
| | e |
| | |
|-----------------------------------------------------|

ToolBarTables change la JTable présentée (bouteilles en cave, cépages,
appellations, adresses)
ToolBarManage change le contenu d'une des JTable (insert, delete,
view...)

--
yt

Avatar
Philippe
Yvon Thoraval wrote:

public class ToolBarTables extends JToolBar implements ActionListener {
...

public JToolBar ToolBarTables() {

//Create the toolbar.
JToolBar toolBar = new JToolBar("Still draggable");
addButtons(toolBar);
toolBar.setFloatable(true);
toolBar.setRollover(true);

System.out.println("ToolBarTables() builded");

return toolBar;
}

...
}


C'est pas ton constructeur ça ! Normal que ça passe jamais dedans
D'ailleurs, ça m'étonnes que ça te mettes pas de warnings...
(nom de méthode identique à la classe)

Je verais plutot :

<CODE>
public class ToolBarTables extends JToolBar implements ActionListener {

public ToolBarTables() {
super("Still draggable");
addButtons(this); // <- a voir, selon comment tu gères ça ...
setFloatable(true);
setRollover(true);
}
// ...
}
</CODE>

--
Philippe

Avatar
yvon.thoravalNO-SPAM
Philippe wrote:

C'est pas ton constructeur ça ! Normal que ça passe jamais dedans
D'ailleurs, ça m'étonnes que ça te mettes pas de warnings...
(nom de méthode identique à la classe)

Je verais plutot :

<CODE>
[...]

}
</CODE>


Ouais, merci, j'ai trouvé mon pb :
<CODE>
public class ToolBarManage extends JPanel implements ActionListener {
protected JTextArea textArea;
protected String newline = "n";

static final private String SEARCH = "Rechercher";
static final private String ADD = "Ajouter";
static final private String EDIT = "Editer";
static final private String VIEW = "Visualiser";
static final private String DELETE = "Suoprimer";

static final private Dimension sepCourt = new Dimension(24, 24);
static final private Dimension sepLong = new Dimension(72, 24);

static final private int HORIZONTAL = 0;
static final private int VERTICAL = 1;

public ToolBarManage() {
super(new BorderLayout());

//Create the toolbar.
JToolBar toolBar = new JToolBar("Still draggable");
addButtons(toolBar);
toolBar.setFloatable(true);
toolBar.setRollover(true);
toolBar.setOrientation(VERTICAL);

add(toolBar, BorderLayout.EAST);
}
[...]
}
</CODE>

j'avais mis ça en JToolBar au lieu de JPanel...

reste un "petit soucis" have a look at :

http://cjoint.com/?jxszL1hcdL

c'est un screenshot qui montre que le toolbar vertical EAST a de la
marge à sa gauche, comment l'éviter ?

d'autre part le toolbar NORTH horizontal, je préférerais que le "?" soit
complétement à droite, y a t'il une directive pour dire ça, remplissage
de toute la place comme avec des springs ???
--
yt

Avatar
Philippe
Yvon Thoraval wrote:
c'est un screenshot qui montre que le toolbar vertical EAST a de la
marge à sa gauche, comment l'éviter ?


Surement un problème dans ton BorderLayout Principal (???)

d'autre part le toolbar NORTH horizontal, je préférerais que le "?" soit
complétement à droite, y a t'il une directive pour dire ça, remplissage
de toute la place comme avec des springs ???


Pour coller ton boutton à droite,
il suffit de mettre une HorizontalGlue avant :

bar.add(new JButton("1"));
bar.add(new JButton("2"));
bar.add(Box.createHorizontalGlue()); // <- !!!
bar.add(new JButton("?"));

ça donne l'effet que tu veux :

|| [ 1 ] [ 2 ] [ ? ] |

Avatar
yvon.thoravalNO-SPAM
Philippe wrote:

c'est un screenshot qui montre que le toolbar vertical EAST a de la
marge à sa gauche, comment l'éviter ?


Surement un problème dans ton BorderLayout Principal (???)


dans ma classe principale j'ai :

<code>
JFrame frame = new JFrame();
final SortedTable view = new SortedTable(model);
view.setMakeIndex(true);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(new JScrollPane(view),
BorderLayout.CENTER);

frame.getContentPane().add(new ToolBarTables(),
BorderLayout.NORTH);

frame.getContentPane().add(new ToolBarManage(),
BorderLayout.EAST);

frame.setSize(600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.validate();
frame.setVisible(true);
</code>

et dans les classes ToolBarTables et ToolBarManage j'ai :

<code>
public ToolBarTables() {
super(new BorderLayout());

//Create the toolbar.
JToolBar toolBar = new JToolBar("Still draggable");
addButtons(toolBar);
toolBar.setFloatable(true);
toolBar.setRollover(true);
toolBar.setOrientation(HORIZONTAL);

add(toolBar, BorderLayout.NORTH);
}
</code>

d'autre part le toolbar NORTH horizontal, je préférerais que le "?" soit
complétement à droite, y a t'il une directive pour dire ça, remplissage
de toute la place comme avec des springs ???


Pour coller ton boutton à droite,
il suffit de mettre une HorizontalGlue avant :

bar.add(Box.createHorizontalGlue()); // <- !!!
[...]


Ouais, merci pour l'info (je ne connaissais pas Box) look here :

<http://cjoint.com/data/jxvdaJ53pq.htm>

bon reste le coin en bas à droite a un pb (sur MacOS X) avec le carré
pour redimensionner la fenêtre...
--
yt


Avatar
Philippe
Yvon Thoraval wrote:
<code>
JFrame frame = new JFrame();
final SortedTable view = new SortedTable(model);
view.setMakeIndex(true);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(new JScrollPane(view),
BorderLayout.CENTER);

frame.getContentPane().add(new ToolBarTables(),
BorderLayout.NORTH);

frame.getContentPane().add(new ToolBarManage(),
BorderLayout.EAST);

frame.setSize(600, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.validate();
frame.setVisible(true);
</code>


essaie de mettre un frame.pack();
avant le frame.setSize(600,400);

Avatar
yvon.thoravalNO-SPAM
Philippe wrote:


essaie de mettre un frame.pack();
avant le frame.setSize(600,400);


ok, merci, mais ça ne change rien...
--
yt

1 2