[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Button problem on Windows xp

Hi all:
I met a strange problem today.I set background and foreground color for
button on linux platform ,It show fine. it doesn't show the color which i
set   when i test it on windows .It shows the default color on the button.
I don't know why it will happens on windows ??   can anyone tell me what's
wrong with it ? you can test these code on windows,

thanks in advance.

 my code as follows: 

public class DBColorSelector {


        Shell shell;
        private static Display display;
        
        private static List<Color> colors;
        private Color tempColor;
        private Label showLabel;
        public Color curColor;
        
        public Color getSelectedColor(){
                return curColor;
        }
        
        private void initColors(){
                if(colors != null){
                        return;
                }
                
                colors = new ArrayList<Color>();
                try{
                        SAXBuilder builder = new SAXBuilder();
                        Document doc = builder.build(DBCOLORCONFIG);
                        Element root = doc.getRootElement();
                        List<Element> list = root.getChildren("color");
                        Iterator<Element> it = list.iterator();
                        while(it.hasNext()){
                                Element color = it.next();
                                Element rgb = color.getChild("rgb");
                                String rgbValue = rgb.getText();
                                
                                int r = Integer.valueOf(rgbValue.substring(0,2),16);
                                int g = Integer.valueOf(rgbValue.substring(2,4),16);
                                int b = Integer.valueOf(rgbValue.substring(4),16);
                                
                                Color tmpColor = new Color(display,r,g,b);
                                colors.add(tmpColor);
                        }
                        
                }catch(Exception e){
                        e.printStackTrace();
                }
 
        }
        
        public DBColorSelector(Shell parent,Color defaultColor){
                initColors();
                
                curColor = defaultColor;
                
                display = parent.getDisplay();
                shell = new Shell(parent,SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
                shell.setText("Database Color Selector");
                shell.setLayout(new GridLayout());
                
                Group colorGroup = new Group(shell,SWT.None);
                colorGroup.setText("Color List");
                colorGroup.setLayout(new GridLayout(4,true));
                
                showLabel=new Label(shell,SWT.BORDER);
                showLabel.setBackground(curColor);
                
                GridData labelData=new GridData();
                labelData.widthHint=100;
                labelData.heightHint=40;
                showLabel.setLayoutData(labelData);
                GridData colorData=new GridData();
                colorData.widthHint=85;
                colorData.heightHint=40;
                        tempColor=colors.get(i);
                        Button cbtn = new Button(colorGroup,SWT.FLAT);
                        cbtn.setBackground(tempColor);
                        
                        cbtn.setForeground(tempColor);

                        cbtn.setLayoutData(colorData);
                        cbtn.addSelectionListener(new SelectionAdapter(){
                                @Override
                                public void widgetSelected(SelectionEvent arg0) {
                                        Button btn=(Button)arg0.getSource();
                                        showLabel.setBackground(btn.getBackground());
                                        curColor = btn.getBackground();
                                        
                                        if(!shell.isDisposed()){
                                                shell.close();
                                        }
                                }
                        });
                        
                }
                
                
        }
        
        public void show() {
                shell.open();
                
                shell.setSize(400,200);
                shell.layout();
                while (!shell.isDisposed()) {
                        if (!display.readAndDispatch()) {
                                display.sleep();
                        }
                }
        }

        
        public static void main(String[] args){
                Display display = new Display();
                Shell shell = new Shell(display);
                
                DBColorSelector dbSelector = new DBColorSelector(shell,new
Color(display,50,60,70));
                dbSelector.show();
        }
}