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

AWT/Swing Java Discussion :

[look] JSplitPane


Sujet :

AWT/Swing Java

  1. #1
    Rédacteur
    Avatar de lunatix
    Homme Profil pro
    Architecte technique
    Inscrit en
    Novembre 2002
    Messages
    1 960
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Architecte technique

    Informations forums :
    Inscription : Novembre 2002
    Messages : 1 960
    Points : 3 736
    Points
    3 736
    Par défaut [look] JSplitPane
    salut

    Voila, je voudrais faire un JSplitPane super discret.
    en fait faudrait que ca soit comme sur cet image
    en imaginant un splitpane entre chaque liste.

    Le probleme, c'est que je n'arrive pas a enlever les effets de relief que le Jsplitpane impose.

    quelqu'un a une idée ?

    merci
    Lunatix

  2. #2
    Gfx
    Gfx est déconnecté
    Expert éminent
    Avatar de Gfx
    Inscrit en
    Mai 2005
    Messages
    1 770
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 770
    Points : 8 178
    Points
    8 178
    Par défaut
    Essaye :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
            SplitPaneUI splitPaneUI = splitPane.getUI();
            if (splitPaneUI instanceof BasicSplitPaneUI) {
                BasicSplitPaneUI basicUI = (BasicSplitPaneUI) splitPaneUI;
                basicUI.getDivider().setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
            }
    Romain Guy
    Android - Mon livre - Mon blog

  3. #3
    Rédacteur
    Avatar de lunatix
    Homme Profil pro
    Architecte technique
    Inscrit en
    Novembre 2002
    Messages
    1 960
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Architecte technique

    Informations forums :
    Inscription : Novembre 2002
    Messages : 1 960
    Points : 3 736
    Points
    3 736
    Par défaut
    Super merci ! c'est nikel
    avec un JXtitledPanel et son DropShadowBorder : c'est beaucoup plus joli que le look normal du JSplitPane

  4. #4
    Gfx
    Gfx est déconnecté
    Expert éminent
    Avatar de Gfx
    Inscrit en
    Mai 2005
    Messages
    1 770
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 770
    Points : 8 178
    Points
    8 178
    Par défaut
    C'est bien pour ca que j'ai force Richard a faire un DropShadowBorder ^^ D'ailleurs, faudrait que je jette un coup d'oeil a DropShadowBorder, on l'a recemment optimise avec un gars de Java2D, il devrait aller BEAUCOUP plus vite maintenant mais je sais pas si on a pose le code dans le CVS de SwingLabs.
    Romain Guy
    Android - Mon livre - Mon blog

  5. #5
    Gfx
    Gfx est déconnecté
    Expert éminent
    Avatar de Gfx
    Inscrit en
    Mai 2005
    Messages
    1 770
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 770
    Points : 8 178
    Points
    8 178
    Par défaut
    Tiens voila le code modifie :

    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
     
    /*
     * $Id: DropShadowBorder.java,v 1.3 2006/01/25 23:00:10 pubcvs Exp $
     *
     * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
     * Santa Clara, California 95054, U.S.A. All rights reserved.
     *
     * This library is free software; you can redistribute it and/or
     * modify it under the terms of the GNU Lesser General Public
     * License as published by the Free Software Foundation; either
     * version 2.1 of the License, or (at your option) any later version.
     * 
     * This library 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
     * Lesser General Public License for more details.
     * 
     * You should have received a copy of the GNU Lesser General Public
     * License along with this library; if not, write to the Free Software
     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     */
     
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Insets;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.geom.RoundRectangle2D;
    import java.awt.image.BufferedImage;
    import java.awt.image.ConvolveOp;
    import java.awt.image.Kernel;
    import java.util.HashMap;
    import java.util.Map;
     
    import javax.swing.UIManager;
    import javax.swing.border.Border;
     
    /**
     * Implements a DropShadow for components. In general, the DropShadowBorder will
     * work with any rectangular components that do not have a default border installed
     * as part of the look and feel, or otherwise. For example, DropShadowBorder works
     * wonderfully with JPanel, but horribly with JComboBox.
     *
     * @author rbair
     */
    public class DropShadowBorder implements Border {
        private static enum Position {TOP, TOP_LEFT, LEFT, BOTTOM_LEFT,
                        BOTTOM, BOTTOM_RIGHT, RIGHT, TOP_RIGHT};
     
        private static final Map<Integer,Map<Position,BufferedImage>> CACHE 
                = new HashMap<Integer,Map<Position,BufferedImage>>();
     
        private final Color lineColor;
        private final int lineWidth;
        private final int shadowSize;
        private final float shadowOpacity;
        private final int cornerSize;
        private final boolean showTopShadow;
        private final boolean showLeftShadow;
        private final boolean showBottomShadow;
        private final boolean showRightShadow;
     
        public DropShadowBorder() {
            this(UIManager.getColor("Control"), 1, 5);
        }
     
        public DropShadowBorder(Color lineColor, int lineWidth, int shadowSize) {
            this(lineColor, lineWidth, shadowSize, .5f, 12, false, false, true, true);
        }
     
        public DropShadowBorder(Color lineColor, int lineWidth, boolean showLeftShadow) {
            this(lineColor, lineWidth, 5, .5f, 12, false, showLeftShadow, true, true);
        }
     
        public DropShadowBorder(Color lineColor, int lineWidth, int shadowSize,
                float shadowOpacity, int cornerSize, boolean showTopShadow,
                boolean showLeftShadow, boolean showBottomShadow, boolean showRightShadow) {
            this.lineColor = lineColor;
            this.lineWidth = lineWidth;
            this.shadowSize = shadowSize;
            this.shadowOpacity = shadowOpacity;
            this.cornerSize = cornerSize;
            this.showTopShadow = showTopShadow;
            this.showLeftShadow = showLeftShadow;
            this.showBottomShadow = showBottomShadow;
            this.showRightShadow = showRightShadow;
        }
     
        /**
         * @inheritDoc
         */
        public void paintBorder(Component c, Graphics graphics, int x, int y, int width, int height) {
            /*
             * 1) Get images for this border
             * 2) Paint the images for each side of the border that should be painted
             */
           	Map<Position,BufferedImage> images = getImages(null);
     
            //compute the edges of the component -- not including the border
            Graphics2D g2 = (Graphics2D)graphics.create();
            g2.setColor(lineColor);
     
            //The location and size of the shadows depends on which shadows are being
            //drawn. For instance, if the left & bottom shadows are being drawn, then
            //the left shadow extends all the way down to the corner, a corner is drawn,
            //and then the bottom shadow begins at the corner. If, however, only the
            //bottom shadow is drawn, then the bottom-left corner is drawn to the
            //right of the corner, and the bottom shadow is somewhat shorter than before.
     
            Point topLeftShadowPoint = null;
            if (showLeftShadow || showTopShadow) {
                topLeftShadowPoint = new Point();
                if (showLeftShadow && !showTopShadow) {
                    topLeftShadowPoint.setLocation(x, y + shadowSize);
                } else if (showLeftShadow && showTopShadow) {
                    topLeftShadowPoint.setLocation(x, y);
                } else if (!showLeftShadow && showTopShadow) {
                    topLeftShadowPoint.setLocation(x + shadowSize, y);
                }
            }
     
            Point bottomLeftShadowPoint = null;
            if (showLeftShadow || showBottomShadow) {
                bottomLeftShadowPoint = new Point();
                if (showLeftShadow && !showBottomShadow) {
                    bottomLeftShadowPoint.setLocation(x, y + height - shadowSize - shadowSize);
                } else if (showLeftShadow && showBottomShadow) {
                    bottomLeftShadowPoint.setLocation(x, y + height - shadowSize);
                } else if (!showLeftShadow && showBottomShadow) {
                    bottomLeftShadowPoint.setLocation(x + shadowSize, y + height - shadowSize);
                }
            }
     
            Point bottomRightShadowPoint = null;
            if (showRightShadow || showBottomShadow) {
                bottomRightShadowPoint = new Point();
                if (showRightShadow && !showBottomShadow) {
                    bottomRightShadowPoint.setLocation(x + width - shadowSize, y + height - shadowSize - shadowSize);
                } else if (showRightShadow && showBottomShadow) {
                    bottomRightShadowPoint.setLocation(x + width - shadowSize, y + height - shadowSize);
                } else if (!showRightShadow && showBottomShadow) {
                    bottomRightShadowPoint.setLocation(x + width - shadowSize - shadowSize, y + height - shadowSize);
                }
            }
     
            Point topRightShadowPoint = null;
            if (showRightShadow || showTopShadow) {
                topRightShadowPoint = new Point();
                if (showRightShadow && !showTopShadow) {
                    topRightShadowPoint.setLocation(x + width - shadowSize, y + shadowSize);
                } else if (showRightShadow && showTopShadow) {
                    topRightShadowPoint.setLocation(x + width - shadowSize, y);
                } else if (!showRightShadow && showTopShadow) {
                    topRightShadowPoint.setLocation(x + width - shadowSize - shadowSize, y);
                }
            }
     
            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
     
            if (showLeftShadow) {
                Rectangle leftShadowRect =
                    new Rectangle(x,
                                  topLeftShadowPoint.y + shadowSize,
                                  shadowSize,
                                  bottomLeftShadowPoint.y - topLeftShadowPoint.y - shadowSize);
                g2.drawImage(images.get(Position.LEFT),
                             leftShadowRect.x, leftShadowRect.y,
                             leftShadowRect.width, leftShadowRect.height, null);
            }
     
            if (showBottomShadow) {
                Rectangle bottomShadowRect =
                    new Rectangle(bottomLeftShadowPoint.x + shadowSize,
                                  y + height - shadowSize,
                                  bottomRightShadowPoint.x - bottomLeftShadowPoint.x - shadowSize,
                                  shadowSize);
                g2.drawImage(images.get(Position.BOTTOM),
                             bottomShadowRect.x, bottomShadowRect.y,
                             bottomShadowRect.width, bottomShadowRect.height, null);
            }
     
            if (showRightShadow) {
                Rectangle rightShadowRect =
                    new Rectangle(x + width - shadowSize,
                                  topRightShadowPoint.y + shadowSize,
                                  shadowSize,
                                  bottomRightShadowPoint.y - topRightShadowPoint.y - shadowSize);
                g2.drawImage(images.get(Position.RIGHT),
                             rightShadowRect.x, rightShadowRect.y,
                             rightShadowRect.width, rightShadowRect.height, null);
            }
     
            if (showTopShadow) {
                Rectangle topShadowRect =
                    new Rectangle(topLeftShadowPoint.x + shadowSize,
                                  y,
                                  topRightShadowPoint.x - topLeftShadowPoint.x - shadowSize,
                                  shadowSize);
                g2.drawImage(images.get(Position.TOP),
                             topShadowRect.x, topShadowRect.y,
                             topShadowRect.width, topShadowRect.height, null);
            }
     
            if (showLeftShadow || showTopShadow) {
                g2.drawImage(images.get(Position.TOP_LEFT),
                             topLeftShadowPoint.x, topLeftShadowPoint.y, null);
            }
            if (showLeftShadow || showBottomShadow) {
                g2.drawImage(images.get(Position.BOTTOM_LEFT),
                             bottomLeftShadowPoint.x, bottomLeftShadowPoint.y, null);
            }
            if (showRightShadow || showBottomShadow) {
                g2.drawImage(images.get(Position.BOTTOM_RIGHT),
                             bottomRightShadowPoint.x, bottomRightShadowPoint.y, null);
            }
            if (showRightShadow || showTopShadow) {
                g2.drawImage(images.get(Position.TOP_RIGHT),
                             topRightShadowPoint.x, topRightShadowPoint.y, null);
            }
     
            g2.dispose();
        }
     
        private Map<Position,BufferedImage> getImages(Graphics2D g2) {
            //first, check to see if an image for this size has already been rendered
            //if so, use the cache. Else, draw and save
            Map<Position,BufferedImage> images = CACHE.get(shadowSize);
            if (images == null) {
                images = new HashMap<Position,BufferedImage>();
     
                /*
                 * Do draw a drop shadow, I have to:
                 *  1) Create a rounded rectangle
                 *  2) Create a BufferedImage to draw the rounded rect in
                 *  3) Translate the graphics for the image, so that the rectangle
                 *     is centered in the drawn space. The border around the rectangle
                 *     needs to be shadowWidth wide, so that there is space for the
                 *     shadow to be drawn.
                 *  4) Draw the rounded rect as black, with an opacity of 50%
                 *  5) Create the BLUR_KERNEL
                 *  6) Blur the image
                 *  7) copy off the corners, sides, etc into images to be used for
                 *     drawing the Border
                 */
                int rectWidth = cornerSize + 1;
                RoundRectangle2D rect = new RoundRectangle2D.Double(0, 0, rectWidth, rectWidth, cornerSize, cornerSize);
                int imageWidth = rectWidth + shadowSize * 2;
                BufferedImage image = new BufferedImage(imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB);
                Graphics2D buffer = (Graphics2D)image.getGraphics();
                buffer.setColor(new Color(0.0f, 0.0f, 0.0f, shadowOpacity));
                buffer.translate(shadowSize, shadowSize);
                buffer.fill(rect);
                buffer.dispose();
     
                float blurry = 1.0f / (float)(shadowSize * shadowSize);
                float[] blurKernel = new float[shadowSize * shadowSize];
                for (int i=0; i<blurKernel.length; i++) {
                    blurKernel[i] = blurry;
                }
                ConvolveOp blur = new ConvolveOp(new Kernel(shadowSize, shadowSize, blurKernel));
                BufferedImage targetImage = new BufferedImage(imageWidth, imageWidth, BufferedImage.TYPE_INT_ARGB);
                ((Graphics2D)targetImage.getGraphics()).drawImage(image, blur, -(shadowSize/2), -(shadowSize/2));
     
                int x = 1;
                int y = 1;
                int w = shadowSize;
                int h = shadowSize;
                images.put(Position.TOP_LEFT, getSubImage(targetImage, x, y, w, h));
                x = 1;
                y = h;
                w = shadowSize;
                h = 1;
                images.put(Position.LEFT, getSubImage(targetImage, x, y, w, h));
                x = 1;
                y = rectWidth;
                w = shadowSize;
                h = shadowSize;
                images.put(Position.BOTTOM_LEFT, getSubImage(targetImage, x, y, w, h));
                x = cornerSize + 1;
                y = rectWidth;
                w = 1;
                h = shadowSize;
                images.put(Position.BOTTOM, getSubImage(targetImage, x, y, w, h));
                x = rectWidth;
                y = x;
                w = shadowSize;
                h = shadowSize;
                images.put(Position.BOTTOM_RIGHT, getSubImage(targetImage, x, y, w, h));
                x = rectWidth;
                y = cornerSize + 1;
                w = shadowSize;
                h = 1;
                images.put(Position.RIGHT, getSubImage(targetImage, x, y, w, h));
                x = rectWidth;
                y = 1;
                w = shadowSize;
                h = shadowSize;
                images.put(Position.TOP_RIGHT, getSubImage(targetImage, x, y, w, h));
                x = shadowSize;
                y = 1;
                w = 1;
                h = shadowSize;
                images.put(Position.TOP, getSubImage(targetImage, x, y, w, h));
     
                image.flush();
            }
            return images;
        }
     
        /**
         * Returns a new BufferedImage that represents a subregion of the given
         * BufferedImage.  (Note that this method does not use
         * BufferedImage.getSubimage(), which will defeat image acceleration
         * strategies on later JDKs.)
         */
        private BufferedImage getSubImage(BufferedImage img,
                                          int x, int y, int w, int h) {
            BufferedImage ret = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = ret.createGraphics();
            g2.drawImage(img,
                         0, 0, w, h,
                         x, y, x+w, y+h,
                         null);
            g2.dispose();
            return ret;
        }
     
        /**
         * @inheritDoc
         */
        public Insets getBorderInsets(Component c) {
            int top = showTopShadow ? lineWidth + shadowSize : lineWidth;
            int left = showLeftShadow ? lineWidth + shadowSize : lineWidth;
            int bottom = showBottomShadow ? lineWidth + shadowSize : lineWidth;
            int right = showRightShadow ? lineWidth + shadowSize : lineWidth;
            return new Insets(top, left, bottom, right);
        }
     
        /**
         * @inheritDoc
         */
        public boolean isBorderOpaque() {
            return true;
        }
     
        public boolean isShowTopShadow() {
            return showTopShadow;
        }
     
        public boolean isShowLeftShadow() {
            return showLeftShadow;
        }
     
        public boolean isShowRightShadow() {
            return showRightShadow;
        }
     
        public boolean isShowBottomShadow() {
            return showBottomShadow;
        }
     
        public int getLineWidth() {
            return lineWidth;
        }
     
        public Color getLineColor() {
            return lineColor;
        }
     
        public int getShadowSize() {
            return shadowSize;
        }
     
        public float getShadowOpacity() {
            return shadowOpacity;
        }
     
        public int getCornerSize() {
            return cornerSize;
        }
    }
    Romain Guy
    Android - Mon livre - Mon blog

  6. #6
    Rédacteur
    Avatar de lunatix
    Homme Profil pro
    Architecte technique
    Inscrit en
    Novembre 2002
    Messages
    1 960
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Architecte technique

    Informations forums :
    Inscription : Novembre 2002
    Messages : 1 960
    Points : 3 736
    Points
    3 736
    Par défaut
    je teste ca dès que j'ai le temps. Matisse est vraiment bien : en deux temps trois mouvements j'ai ajouté tous ces composants a la palette : top

    puisque tu es la, je me permets de te dire que le site swinglabs a plein de liens morts, et que c'est pas top ! (les weekly build de swingX par exemple, ou les demos de swingX).

    En tous cas, un gros merci pour ton aide

  7. #7
    Gfx
    Gfx est déconnecté
    Expert éminent
    Avatar de Gfx
    Inscrit en
    Mai 2005
    Messages
    1 770
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2005
    Messages : 1 770
    Points : 8 178
    Points
    8 178
    Par défaut
    www.swinglabs.org tu veux dire ? Si oui, c'est parce que j'ai jamais fini le design du site et que je devrais mais que j'en avais marre de faire du Photoshop et des CSS
    Romain Guy
    Android - Mon livre - Mon blog

Discussions similaires

  1. [Look and feel] Texte des JLabels en gras
    Par aliasjcdenton dans le forum AWT/Swing
    Réponses: 11
    Dernier message: 26/01/2006, 11h49
  2. [débutant][JSplitPane] Centrage des composants
    Par gcore dans le forum Agents de placement/Fenêtres
    Réponses: 4
    Dernier message: 17/06/2004, 19h11
  3. [look and feel] Ou les trouver ?
    Par olive.m dans le forum AWT/Swing
    Réponses: 4
    Dernier message: 08/03/2004, 18h42
  4. Nouveau look and feel
    Par julian_ross dans le forum JBuilder
    Réponses: 6
    Dernier message: 16/12/2003, 15h55
  5. Jbuilder9 Look and feel de borland
    Par wsrudmen dans le forum JBuilder
    Réponses: 6
    Dernier message: 26/06/2003, 18h07

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