IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Agents de placement/Fenêtres Java Discussion :

probleme d'affichage de toolbar et menu


Sujet :

Agents de placement/Fenêtres Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Septembre 2008
    Messages
    145
    Détails du profil
    Informations personnelles :
    Âge : 68

    Informations forums :
    Inscription : Septembre 2008
    Messages : 145
    Par défaut probleme d'affichage de toolbar et menu
    bonjour,

    j'ai un menu et une status barre qui fonctionne très bien, j'essai de rajouter un jtoolbar et alors si je le place au nord je perd le menu et si je le place au sud je perd le status, grrrr, moi je perds patience... lol si quelqu'un peut me dire d'ou ca vient ?

    merci d'avance

    greg

  2. #2
    Membre Expert Avatar de guigui5931
    Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2006
    Messages
    1 667
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 667
    Par défaut
    J'aurais tendance a dire que c'est parce que ton menu est déjà au nord et que ton status est déjà au sud.
    Peut tu nous montrer ton code et nous dire ce que tu veux faire avec ton jtoolbar ?

  3. #3
    Membre confirmé
    Inscrit en
    Septembre 2008
    Messages
    145
    Détails du profil
    Informations personnelles :
    Âge : 68

    Informations forums :
    Inscription : Septembre 2008
    Messages : 145
    Par défaut le code
    merci,

    voici le code, heu, je suis débutant... le toolbar je voudrai mettre 4/5 boutons, 3/4 textinput déplacable et si possible le mettre au sud au début, mais effectivement j'ai le status au sud ! on peut pas en mettre 2 ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    // Java & Bézier
    // (C) 2002 Emmanuel Turquin
    //
    // Main.java
    //
    // This program is free software; you can redistribute it and/or modify
    // it under the terms of the GNU General Public License as published by
    // the Free Software Foundation; either version 2 of the License, or
    // (at your option) any later version.
    //
    // This program is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.
    //
    // You should have received a copy of the GNU General Public License
    // along with this program; if not, write to the Free Software
    // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     
    package Ma;
     
    import java.awt.*;
     
    import javax.swing.*;
     
    import java.awt.event.*;
    import java.applet.Applet;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.net.URL;
     
    import jnb.*;
    import extended_classes.*;
     
    public class Main extends JApplet implements ActionListener{
     
    	protected static final String	version = "1.0";
     
    	protected static JnBPanel	panel;
    	protected static MenuBar	menuBar;
    	protected static StatusBar	statusBar;
    	//protected static JPanel 	toolBar;
    	protected static File_g file_g;
    	protected static int	windowWidth = 640;
    	protected static int	windowHeight = 580;
    	protected JTextArea textArea;
    	protected String newline = "\n";
     
    	public void init(){
    		//Try to get window's width and height from applet parameters.
    		try {
    			String windowWidthString = getParameter("WIDTH");
     
    			if (windowWidthString != null) {
    				try {
    					windowWidth = Integer.parseInt(windowWidthString);
    				} catch (NumberFormatException e) {
    					//Use default width.
    				}
    			}
    		} catch (NullPointerException e) {
    			//Applet used as a stand-alone program, no parameter.
    		}
    		try {
    			String windowHeightString = getParameter("HEIGHT");
     
    			if (windowHeightString != null) {
    				try {
    					windowHeight = Integer.parseInt(windowHeightString);
    				} catch (NumberFormatException e) {
    					//Use default width.
    				}
    			}
    		} catch (NullPointerException e) {
    			//Applet used as a stand-alone program, no parameter.
    		}
     
    		//Initialize the layout.
    		getContentPane().setLayout(new BorderLayout());
    		panel = new JnBPanel();
    		getContentPane().add(panel);
     
    		//Initialize the Menu bar.
    		menuBar = new MenuBar();
    		getContentPane().add("North", menuBar);
     
    		//Initialize the Tool bar
     
    		JToolBar toolBar = new JToolBar("Still draggable");
    		addButtons(toolBar);
    		toolBar.setFloatable(true);
    		toolBar.setRollover(true);
     
    		//Create the text area used for output.  Request
    		//enough space for 5 rows and 30 columns.
    		/*textArea = new JTextArea(5, 30);
    		textArea.setEditable(false);
    		JScrollPane scrollPane = new JScrollPane(textArea);
     
    		//Lay out the main panel.
    		setPreferredSize(new Dimension(450, 130));
    		add(toolBar, BorderLayout.PAGE_START);
    		add(scrollPane, BorderLayout.CENTER);
     
     
    */
    		getContentPane().add("East", toolBar);
     
    		//Initialize the Status bar.
    		statusBar = new StatusBar("Welcome to Java & Bézier " + version + "!");
    		getContentPane().add("South", statusBar);
     
     
    	}
     
     
    	static final private String PREVIOUS = "previous";
    	static final private String UP = "up";
    	static final private String NEXT = "next";
    	static final private String SOMETHING_ELSE = "other";
    	static final private String TEXT_ENTERED = "text";
     
     
    	protected void addButtons(JToolBar toolBar) {
    		JButton button = null;
     
    		//first button
    		button = makeNavigationButton("Back24", PREVIOUS,
    				"Back to previous something-or-other",
    		"Previous");
    		toolBar.add(button);
     
    		//second button
    		button = makeNavigationButton("Up24", UP,
    				"Up to something-or-other",
    		"Up");
    		toolBar.add(button);
     
    		//third button
    		button = makeNavigationButton("Forward24", NEXT,
    				"Forward to something-or-other",
    		"Next");
    		toolBar.add(button);
     
    		//separator
    		toolBar.addSeparator();
     
    		//fourth button
    		button = new JButton("Another button");
    		button.setActionCommand(SOMETHING_ELSE);
    		button.setToolTipText("Something else");
    		button.addActionListener(this);
    		toolBar.add(button);
     
    		//fifth component is NOT a button!
    		JTextField textField = new JTextField("A text field");
    		textField.setColumns(10);
    		textField.addActionListener(this);
    		textField.setActionCommand(TEXT_ENTERED);
    		toolBar.add(textField);
    	}
     
    	protected JButton makeNavigationButton(String imageName,
    			String actionCommand,
    			String toolTipText,
    			String altText) {
    		//Look for the image.
    		String imgLocation = "images/"
    			+ imageName
    			+ ".gif";
    		URL imageURL = ToolBarDemo2.class.getResource(imgLocation);
     
    		//Create and initialize the button.
    		JButton button = new JButton();
    		button.setActionCommand(actionCommand);
    		button.setToolTipText(toolTipText);
    		button.addActionListener(this);
     
    		if (imageURL != null) {                      //image found
    			button.setIcon(new ImageIcon(imageURL, altText));
    		} else {                                     //no image found
    			button.setText(altText);
    			System.err.println("Resource not found: "
    					+ imgLocation);
    		}
     
    		return button;
    	}
     
    	public void actionPerformed(ActionEvent e) {
    		String cmd = e.getActionCommand();
    		String description = null;
     
    		// Handle each button.
    		if (PREVIOUS.equals(cmd)) { //first button clicked
    			description = "taken you to the previous <something>.";
    		} else if (UP.equals(cmd)) { // second button clicked
    			description = "taken you up one level to <something>.";
    		} else if (NEXT.equals(cmd)) { // third button clicked
    			description = "taken you to the next <something>.";
    		} else if (SOMETHING_ELSE.equals(cmd)) { // fourth button clicked
    			description = "done something else.";
    		} else if (TEXT_ENTERED.equals(cmd)) { // text field
    			JTextField tf = (JTextField)e.getSource();
    			String text = tf.getText();
    			tf.setText("");
    			description = "done something with this text: "
    				+ newline + "  \""
    				+ text + "\"";
    		}
     
    		displayResult("If this were a real app, it would have "
    				+ description);
    	}
    	protected void displayResult(String actionDescription) {
    		textArea.append(actionDescription + newline);
    		textArea.setCaretPosition(textArea.getDocument().getLength());
    	}
     
    	public static void main(String s[]) {
    		JFrame f = new JFrame("Java & Bézier " + version);
    		JApplet applet = new Main();
     
    		f.addWindowListener(new WindowAdapter() {
    			public void windowClosing(WindowEvent e) {System.exit(0);}
    		});
    		f.getContentPane().add(applet, BorderLayout.CENTER);
    		f.pack();
    		f.setSize(new Dimension(windowWidth, windowHeight));
    		applet.init();
    		f.setVisible(true);
    	}
    }
     
     
    class JnBPanel extends JPanel implements MouseListener, MouseMotionListener{
     
    	BufferedImage		bi;
    	Graphics2D			big;
    	boolean			firstTime = true;
    	boolean			pressOut = false;
    	boolean			mouseOutside = false;
    	boolean			antiAliasing = true;
    	Board2D			board;
    	protected int		width, height;
     
    	public JnBPanel(){
     
    		setBackground(Color.white);
    		addMouseMotionListener(this);
    		addMouseListener(this);
    	}
     
    	public void mousePressed(MouseEvent e){
    		int i;
     
    		//BUTTON1 or BUTTON2
    		if ((e.getModifiers() & (InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK)) > 0){
    			if (board.isVisible()){
    				if ((i = board.contains(e.getX(), e.getY())) >= 0){
    					board.setCurrent(i);
     
    					Point2DList pl =  (Point2DList)board.getCurrent();
     
    					pl.setCurrent(pl.contains(e.getX(), e.getY()));
    					Main.statusBar.displayMsg("Point (X:" + e.getX() + ", Y:" + e.getY() + ") selected.");
    					updateLocation(e);
    				}
    				else {
    					if (board.size() == 0 || (e.getModifiers() & InputEvent.BUTTON2_MASK) > 0){
    						Point2DList pl = new Point2DList();
     
    						board.add(pl);
    					}
    					Point2DList pl =  (Point2DList)board.getCurrent();
    					jnb.Point2D point = new jnb.Point2D(e.getX(), e.getY());
     
    					pl.add(pl.getCurrentIndex() + 1, point);
    					Main.statusBar.displayMsg("Point (X:" + e.getX() + ", Y:" + e.getY() + ") added.");
    				}
    			}
    			else {
    				pressOut = true;	
    			}
    		}
     
    		//BUTTON3
    		else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) > 0){
    			if(board.isVisible()){
    				if ((i = board.contains(e.getX(), e.getY())) >= 0){
    					Point2DList pl =  (Point2DList)board.get(i);
    					if (pl.remove(pl.contains(e.getX(), e.getY())) == 1)
    						board.remove(pl);
    					else
    						board.setActive(pl);
    					Main.statusBar.displayMsg("Point (X:" + e.getX() + ", Y:" + e.getY() + ") removed.");
    					repaint();
    				}
    			}
    		}
    	}
     
    	public void mouseDragged(MouseEvent e){
    		if((e.getModifiers() & (InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK)) > 0 && !mouseOutside && !pressOut) {
    			updateLocation(e);
    		}
    	}
     
    	public void mouseReleased(MouseEvent e){
    		if(board.isVisible() && ((e.getModifiers() & InputEvent.BUTTON3_MASK) == 0)){
    			updateLocation(e);
    		}
    		else {
    			pressOut = false;
    		}
    	}
     
    	public void mouseMoved(MouseEvent e){
    		Main.statusBar.displayMsgBG("(X:" + e.getX() + ", Y:" + e.getY() + ")");
    	}
     
    	public void mouseExited(MouseEvent e){
    		mouseOutside = true;
    	}
     
    	public void mouseEntered(MouseEvent e){
    		mouseOutside = false;
    	}
     
    	public void mouseClicked(MouseEvent e){}
     
    	public void updateLocation(MouseEvent e){
    		Dimension dim = getSize();
    		Point2DList pl =  (Point2DList)board.getCurrent();
     
    		if (pl == null)
    			return;
     
    		jnb.Point2D point = (jnb.Point2D)pl.getCurrent();
    		int x, y;
     
    		if (board.getGrid()){
    			x = jnb.Math.round(e.getX(), board.getGridSpacing());
    			y = jnb.Math.round(e.getY(), board.getGridSpacing());
    		} else {
    			x = e.getX();
    			y = e.getY();
    		}
    		Main.statusBar.displayMsgBG("Point moved to (X:" + x + ", Y:" + y + ").");
    		if ((e.getModifiers() & InputEvent.BUTTON1_MASK) > 0)
    			point.setLocation(x, y, dim);
    		else if ((e.getModifiers() & InputEvent.BUTTON2_MASK) > 0)
    			pl.setLocation(x, y, dim);
    		repaint();
    	}
     
    	public boolean isAntiAliased() {
    		return antiAliasing;
    	}
     
    	public void setAntiAliasing(boolean aa) {
    		antiAliasing = aa;
    		if (antiAliasing)
    			big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    		else
    			big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);	
    	}
     
    	public void paintComponent(Graphics g){
    		super.paintComponent(g);
    		update(g);
    	}
     
    	public void update(Graphics g){
    		Dimension dim = getSize();
    		int w = dim.width;
    		int h = dim.height;
     
    		if(firstTime){
    			width = w;
    			height = h;
    			board = new Board2D(dim);
    			bi = (BufferedImage)createImage(w, h);
    			big = bi.createGraphics();
    			big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    			big.setColor(Color.white);
    			firstTime = false;
    		}
    		if (w != width || h != height) {
    			width = w;
    			height = h;
    			board.setDimension(dim);
    			bi = (BufferedImage)createImage(w, h);
    			big = bi.createGraphics();
    			big.setColor(Color.white);
    		}
     
    		// Clears the drawing area.
    		big.clearRect(0, 0, w, h);
     
    		// Draws and fills the points and curve(s) on the board.
    		board.draw(big);
     
    		// Draws the buffered image to the screen.
    		g.drawImage(bi, 0, 0, this);
    	}
    }

  4. #4
    Membre Expert Avatar de guigui5931
    Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2006
    Messages
    1 667
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 667
    Par défaut
    Dans le cas d'un BorderLayout (ton layout) on ne peut mettre qu'un composant par direction. Un composant peut être un bouton, un input ou un JPanel.
    Ce que tu peux faire c'est mettre ton status et ta toolbar sur un JPanel (avec le layout qui te va bien pour ton affichage) et mettre ce JPanel au sud de ton Panel principal.

  5. #5
    Membre confirmé
    Inscrit en
    Septembre 2008
    Messages
    145
    Détails du profil
    Informations personnelles :
    Âge : 68

    Informations forums :
    Inscription : Septembre 2008
    Messages : 145
    Par défaut merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Probleme d'affichage de menu.
    Par sbedhy dans le forum Débuter
    Réponses: 2
    Dernier message: 16/04/2010, 13h13
  2. Probleme d'affichage de menu
    Par samaxnet dans le forum Zend_Form
    Réponses: 2
    Dernier message: 27/11/2009, 16h02
  3. probleme d'affichage des sous menu! FF/IE7/IE6
    Par hybride1106 dans le forum Mise en page CSS
    Réponses: 1
    Dernier message: 04/09/2007, 10h47
  4. probleme d'affichage de menu
    Par apgjyb dans le forum Excel
    Réponses: 7
    Dernier message: 16/06/2007, 21h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo