Changing GraphicsEnvironment

Folks, hope you are all well.
I am interested in understanding more about the GraphicsEnvironment class. I use MacOsX which has a class apple.awt.CGraphicsEnvironment as the implementer of the abstract class. I have made a no-additional-op subclass of this called MeSsian.drawing.VerboseGraphicsEnvironment which compiles fine.
when i issue the command:
"java -Djava.awt.graphicsenv=MeSsian.drawing.VerboseGraphicsEnvironment MeSsian.drawing.TableauGraphics"
i get the following output then stack trace: -
ok
/ * this shows that a simple try block of the statement Class.forName("MeSsian.drawing.VerboseGraphicsEnvironment"); has found the class ok
Exception in thread "main" java.lang.Error: Could not find class: MeSsian.drawing.VerboseGraphicsEnvironment
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
at apple.awt.CToolkit.getScreenWidth(CToolkit.java:680)
at sun.awt.SunToolkit.getScreenSize(SunToolkit.java:385)
at MeSsian.gui.Screen.getSize(Screen.java:8)
at MeSsian.gui.Screen.getSizeForAWindowOfProportion(Screen.java:11)
at MeSsian.gui.componenthosting.DefaultHost.<init>(DefaultHost.java:47)
at MeSsian.gui.componenthosting.BoundHost.getMeAHost(BoundHost.java:16)
at MeSsian.drawing.TableauGraphics.main(TableauGraphics.java:96)
This suggests to me that the system has recognised the system property ok, and is trying to act on it.
Why can the system find the class for purposes of loading it in, but when it comes to the getLocal... etc call, it can't find ir? can anyone replicate this and explain whats going on?
Many thanks

Apple's class may belong to a sealed package -- though I actually don't know why you get the error. It must be somethng like this -- an access problem.
There may be restrictions on how the GraphicsEnvironment is instantiated and installed. Search for advanced tips on Sun's site.
Good Luck!
- Steev.

Similar Messages

  • How to change font/ font color etc in a graphic object using JCombobox?

    Hello
    My program im writing recently is a small tiny application which can change fonts, font sizes, font colors and background color of the graphics object containing some strings. Im planning to use Jcomboboxes for all those 4 ideas in implementing those functions. Somehow it doesnt work! Any help would be grateful.
    So currently what ive done so far is that: Im using two classes to implement the whole program. One class is the main class which contains the GUI with its components (Jcomboboxes etc..) and the other class is a class extending JPanel which does all the drawing. Therefore it contains a graphics object in that class which draws the string. However what i want it to do is using jcombobox which should contain alit of all fonts available/ font sizes/ colors etc. When i scroll through the lists and click the one item i want - the graphics object properties (font sizes/ color etc) should change as a result.
    What ive gt so far is implemented the jcomboboxes in place. Problem is i cant get the font to change once selecting an item form it.
    Another problem is that to set the color of font - i need to use it with a graphics object in the paintcomponent method. In this case i dnt want to create several diff paint.. method with different property settings (font/ size/ color)
    Below is my code; perhaps you'll understand more looking at code.
    public class main...
    Color[] Colors = {Color.BLUE, Color.RED, Color.GREEN};
            ColorList = new JComboBox(Colors);
    ColorList.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ev) {
                     JComboBox cb = (JComboBox)ev.getSource();
                    Color colorType = (Color)cb.getSelectedItem();
                    drawingBoard.setBackground(colorType);
              });;1) providing the GUI is correctly implemented with components
    2) Combobox stores the colors in an array
    3) ActionListener should do following job: (but cant get it right - that is where my problem is)
    - once selected the item (color/ font size etc... as i would have similar methods for each) i want, it should pass the item into the drawingboard class (JPanel) and then this class should do the job.
    public class DrawingBoard extends JPanel {
           private String message;
           public DrawingBoard() {
                  setBackground(Color.white);
                  Font font = new Font("Serif", Font.PLAIN, fontSize);
                  setFont(font);
                  message = "";
           public void setMessage(String m) {
                message = m;
                repaint();
           public void paintComponent(Graphics g) {
                  super.paintComponent(g);
                  //setBackground(Color.RED);
                  Graphics2D g2 = (Graphics2D) g;
                  g2.setRenderingHint             
                  g2.drawString(message, 50, 50);
           public void settingFont(String font) {
                //not sure how to implement this?                          //Jcombobox should pass an item to this
                                   //it should match against all known fonts in system then set that font to the graphics
          private void settingFontSize(Graphics g, int f) {
                         //same probelm with above..              
          public void setBackgroundColor(Color c) {
               setBackground(c);
               repaint(); // still not sure if this done corretly.
          public void setFontColor(Color c) {
                    //not sure how to do this part aswell.
                   //i know a method " g.setColor(c)" exist but i need to use a graphics object - and to do that i need to pass it in (then it will cause some confusion in the main class (previous code)
           My problems have been highlighted in the comments of code above.
    Any help will be much appreciated thanks!!!

    It is the completely correct code
    I hope that's what you need
    Just put DrawingBoard into JFrame and run
    Good luck!
    public class DrawingBoard extends JPanel implements ActionListener{
         private String message = "message";
         private Font font = new Font("Serif", Font.PLAIN, 10);
         private Color color = Color.RED;
         private Color bg = Color.WHITE;
         private int size = 10;
         public DrawingBoard(){
              JComboBox cbFont = new JComboBox(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
              cbFont.setActionCommand("font");
              JComboBox cbSize = new JComboBox(new Integer[]{new Integer(14), new Integer(13)});
              cbSize.setActionCommand("size");
              JComboBox cbColor = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbColor.setActionCommand("color");
              JComboBox cbBG = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbBG.setActionCommand("bg");
              add(cbFont);
              cbFont.addActionListener(this);
              add(cbSize);
              cbSize.addActionListener(this);
              add(cbColor);
              cbColor.addActionListener(this);
              add(cbBG);
              cbBG.addActionListener(this);
         public void setMessage(String m){
              message = m;
              repaint();
         protected void paintComponent(Graphics g){
              super.paintComponent(g);
              Graphics2D g2 = (Graphics2D)g;
              g2.setColor(bg);//set background color
              g2.fillRect(0,0, getWidth(), getHeight());          
              g2.setColor(color);//set text color
              FontRenderContext frc = g2.getFontRenderContext();
              TextLayout tl = new TextLayout(message,font,frc);//set font and message
              AffineTransform at = new AffineTransform();
              at.setToTranslation(getWidth()/2-tl.getBounds().getWidth()/2,
                        getWidth()/2 + tl.getBounds().getHeight()/2);//set text at center of panel
              g2.fill(tl.getOutline(at));
         public void actionPerformed(ActionEvent e){
              JComboBox cb = (JComboBox)e.getSource();
              if (e.getActionCommand().equals("font")){
                   font = new Font(cb.getSelectedItem().toString(), Font.PLAIN, size);
              }else if (e.getActionCommand().equals("size")){
                   size = ((Integer)cb.getSelectedItem()).intValue();
              }else if (e.getActionCommand().equals("color")){
                   color = (Color)cb.getSelectedItem();
              }else if (e.getActionCommand().equals("bg")){
                   bg = (Color)cb.getSelectedItem();
              repaint();
    }

  • How do I change fonts in a Text field ??

    Okay I've tried to implement a JComboBox that allows the user to change fonts in the text field. So far I've tried different methods to do it but to no avail. Could somebodoy here read the programs source code for me and tell me where I went wrong?
    /* * My GUI Client */
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import javax.swing.event.*;
    //for HTML Headers
    import javax.swing.text.StyledEditorKit.*;
    import javax.swing.text.html.HTMLEditorKit.*;
    import javax.swing.text.html.*;
    import javax.swing.event.HyperlinkListener;
    import javax.swing.event.HyperlinkEvent;
    import javax.swing.event.HyperlinkEvent.EventType;
    import javax.swing.text.html.HTMLFrameHyperlinkEvent;
    //for layout managers
    import java.awt.event.*;
    //for action and window events
    import java.io.*;
    import java.net.*;
    import java.awt.GraphicsEnvironment;
    //for font settings
    import java.lang.Integer;
    import java.util.Vector;
    import java.awt.font.*;
    import java.awt.geom.*;
    public class guiClient extends JFrame implements ActionListener {
    protected static final String textFieldString = "JTextField";
    protected static final String loadgraphicString = "LoadGraphic";
    protected static final String connectString = "Connect";
    static JEditorPane editorPane;
    static JPanel layoutPanel = new JPanel(new BorderLayout());
    static JPanel controlPanel = new JPanel(new BorderLayout());
    static JPanel buttonPanel = new JPanel(new BorderLayout());
    static JPanel fontPanel = new JPanel(new BorderLayout());
    static PrintStream out;
    static DrawPanel dPanel;
    static DrawPanel dPButton;
    static DrawPanel dFonts;
    static DrawControls dControls;
    static DrawButtons dButtons;
    static String userString;
    static String currentFont;
    String fontchoice;
    String fontlist;
    static JTextField userName = new JTextField();
    public static JMenuBar menuBar;
    private static JButton connectbutton = new JButton("Connect");
    static boolean CONNECTFLAG = false;
    //create the gui interface
    public guiClient() {
         super("My Client");
    // Create a ComboBox
    GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String envfonts[] = gEnv.getAvailableFontFamilyNames();
    Vector vector = new Vector();
    for ( int i = 1; i < envfonts.length; i++ ) {
    vector.addElement(envfonts);
    JComboBox fontlist = new JComboBox (envfonts);
         fontlist.setSelectedIndex(0);
         fontlist.setEditable(true);
         fontlist.addActionListener(this);
         fontchoice = envfonts[0];     
    //Create a regular text field.
         JTextField textField = new JTextField(10);
         textField.setActionCommand(textFieldString);
         textField.addActionListener(this);          
    //Create an editor pane.
    editorPane = new JEditorPane();
         editorPane.setContentType("text");
         editorPane.setEditable(false);
    //set up HTML editor kit
         HTMLDocument m_doc = new HTMLDocument();
         editorPane.setDocument(m_doc);
         HTMLEditorKit hkit = new HTMLEditorKit();
         editorPane.setEditorKit( hkit );
         editorPane.addHyperlinkListener( new HyperListener());
    //Create whiteboard
    dPanel = new DrawPanel();
    dPButton = new DrawPanel();
    dFonts = new DrawPanel();
    dControls = new DrawControls(dPanel);
    dButtons = new DrawButtons(dPButton);
         //JLable fontLab = new JLabel(fontLable);
    //fontLab.setText("Fonts");
    //Font newFont = getFont().deriveFont(1);
    //fontLab.setFont(newFont);
    //fontLab.setHorizontalAlignment(JLabel.CENTER);
    JPanel whiteboard = new JPanel();
    whiteboard.setLayout(new BorderLayout());
    whiteboard.setPreferredSize(new Dimension(300,300));
    whiteboard.add("Center",dPanel);
    whiteboard.add("South",dControls);
    whiteboard.add("North",dButtons);
         JScrollPane editorScrollPane = new JScrollPane(editorPane);
         editorScrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
         editorScrollPane.setPreferredSize(new Dimension(250, 145));
         editorScrollPane.setMinimumSize(new Dimension(50, 50));
    //put everything in a panel
         JPanel contentPane = new JPanel();
         JPanel fontPane = new JPanel();
         contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    //add whiteboard
         contentPane.add(whiteboard);
    //add editor box
         contentPane.add(editorScrollPane);
    //add spacer
         contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    //add textfield
         contentPane.add(textField);
    //set up layout pane
         //layoutPanel.add(GridLayout(2,1),fontLab);
         layoutPanel.add( BorderLayout.NORTH, fontlist);     
         layoutPanel.add(BorderLayout.WEST,new Label("Name: ")); //add a label
         layoutPanel.add(BorderLayout.CENTER, userName ); //add textfield for user names
         layoutPanel.add(BorderLayout.SOUTH, connectbutton);//add dropdown box for fonts
         //fontPane.add(BorderLayout.NORTH,fontlist);
         contentPane.add(layoutPanel);
         contentPane.add(controlPanel);
         contentPane.add(buttonPanel);
    //Create the menu bar.
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    //Build the first menu.
         JMenu menu = new JMenu("File");
         menu.setMnemonic(KeyEvent.VK_F);
         menuBar.add(menu);
    //a group of JMenuItems
         JMenuItem menuItem = new JMenuItem("Load Graphic", KeyEvent.VK_L);
         menu.add(menuItem);
    menuItem.setActionCommand(loadgraphicString);
         menuItem.addActionListener(this);
    connectbutton.setActionCommand(connectString);
    connectbutton.addActionListener(this);
         setContentPane(contentPane);
    static private void insertTheHTML(JEditorPane editor, String html, int location) throws IOException {
         HTMLEditorKit kit = (HTMLEditorKit) editor.getEditorKit();
         Document doc = editor.getDocument();
         StringReader reader = new StringReader(html);
         try {
              kit.read(reader, doc, location);
         } catch (BadLocationException e) {}
    //listen for actions being performed and process them
    public void actionPerformed(ActionEvent e) {
    //if the action is from the textfield (e.g. user hits enter)
         if (e.getActionCommand().equals(textFieldString)) {
              JTextField fromUser = (JTextField)e.getSource();
         if (fromUser != null){
    //place user text in editor pane
    //send message to server
                   if (userName.getText() != null) {
                        userString = userName.getText().trim();
                   out.println(userString + ": " + fromUser.getText());
              fromUser.setText("");
         } else if(e.getActionCommand().equals(connectString)) {
              CONNECTFLAG = true;
    } else if (e.getActionCommand().equals(loadgraphicString) ) {
              final JFileChooser fc = new JFileChooser();
              int returnVal = fc.showOpenDialog(this);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
                   File file = fc.getSelectedFile();
                   dPanel.loadImage(file.getAbsolutePath());
                   sendImage(file);
         else if (e.getActionCommand().equals(fontlist)){
         JComboBox cb = (JComboBox)e.getSource();
    String newSelection = (String)cb.getSelectedItem();
    currentFont = newSelection;
         userString = currentFont;
    return;
    /*public void itemStateChanged (ItemEvent e) {
    if ( e.getStateChange() != ItemEvent.SELECTED ) {
    return;
    if ( list == fontlist ) {
    fontchoice = (String)fontlist.getSelectedItem();
         userString.changeFont(fontchoice);
    //append text to the editor pane and put it at the bottom
    public static void appendText(String text) {
         if (text.startsWith("ID ") ) {
              userString = text.substring(3);
         } else if (text.startsWith("DRAW ") ) {
              if (text.regionMatches(5,"LINE",0,4)) {
    dPanel.processLine(text);
         }else if (text.regionMatches(5,"POINTS",0,5)) {
         dPanel.processPoint(text);
         } else if (text.startsWith("IMAGE ") ) {
    int len = (new Integer( text.substring(6, text.indexOf(",")))).intValue();
    //get x and y coordinates
         byte[] data = new byte[ (int)len ];
         int read = 0;
    try {
         while (read < len) {
         data = text.getBytes( text.substring(0, len) );
    } catch (Exception e) {}
         Image theImage = null;
         theImage = dPanel.getToolkit().createImage(data);
         dPanel.getToolkit().prepareImage(theImage, -1, -1, dPanel);
         while ((dPanel.getToolkit().checkImage(theImage, -1, -1, dPanel) & dPanel.ALLBITS) == 0) {}
              dPanel.drawPicture(0, 0, theImage);
    } else {
    //set current position in editorPane to the end
              editorPane.setCaretPosition(editorPane.getDocument().getLength());
    //put text into the editorPane
              try {
                   insertTheHTML(editorPane, text, editorPane.getDocument().getLength());
              } catch (IOException e) {}
    } //end of appendText(String)
    public void sendImage(File file) {
    //find length of file
         long len = file.length();
    //read file into byte array
         byte[] byteArray = new byte[(int)len];
         try {
              FileInputStream fstream = new FileInputStream(file);
              if (fstream.read(byteArray) < len) {
    //error could not load file
              } else {
              out.println("IMAGE " + len + ",");
                   out.write(byteArray, 0, (int)len); //write file to stream
         } catch(Exception e){}
    //run the client
    public static void main(String[] args) {
         String ipAddr=null, portNr=null;
              if (args.length != 2) {
                   System.out.println("USAGE: java guiClient IP_Address port_number");
                   System.exit(0);
              } else {
         ipAddr = args[0];
              portNr = args[1];
              JFrame frame = new guiClient();
              frame.addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) { System.exit(0); }
              frame.pack();
              frame.setVisible(true);
              while(CONNECTFLAG == false){}
    //sames as previous client,
    //set up connection and then listen for messages from the Server
              String socketIP = ipAddr;
              int port = Integer.parseInt(portNr);
    //the IP address of the machine where the server is running
              Socket theSocket = null;
    //communication line to the server
              out = null;
    //for message sending
              BufferedReader in = null;
    //for message receiving
              try {
              theSocket = new Socket(socketIP, port );
    //try to connect
              out = new PrintStream(theSocket.getOutputStream());
                   dPanel.out = out;
    //for client to send messages
              in = new BufferedReader(new InputStreamReader(theSocket.getInputStream()));
                   BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in));
                   String fromServer;
                   while ((fromServer = in.readLine()) != null) {
                   appendText(fromServer);
                   if (fromServer.equals("BYE")) {
                        appendText("Connection Closed");
                        break;
              out.close();
    //close all streams
              in.close();
              theSocket.close();
    //close the socket
         } catch (UnknownHostException e) {
    //if the socket cannot be openned
              System.err.println("Cannot find " + socketIP);
              System.exit(1);
              } catch (IOException e) { //if the socket cannot be read or written
              System.err.println("Could not make I/O connection with " + socketIP);
              System.exit(1);
    class HyperListener implements HyperlinkListener {
    public JEditorPane sourcePane;
    public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
    sourcePane = (JEditorPane) e.getSource();
                   if (e instanceof HTMLFrameHyperlinkEvent) {
    HTMLFrameHyperlinkEvent event = (HTMLFrameHyperlinkEvent) e;
                        System.out.println(event.getTarget());
                        HTMLDocument doc = (HTMLDocument) sourcePane.getDocument();
                        doc.processHTMLFrameHyperlinkEvent(event);
    else {
    try {}
    catch (Exception ev){
         ev.printStackTrace();
    Well sorry the source code takes up the whole forum but I need a good feedback from this.

    All right...
    public class guiClient extends JFrame implements ActionListener {
    static String userString;
    static String currentFont;
    String fontchoice;
    String fontlist;
    static JTextField userName = new JTextField();
    public guiClient() {
         super("My Client");
    public guiClient() {
         super("My Client");
    // Create a ComboBox
    GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String envfonts[] = gEnv.getAvailableFontFamilyNames();
    Vector vector = new Vector();
    for ( int i = 1; i < envfonts.length; i++ ) {
    vector.addElement(envfonts);
    JComboBox fontlist = new JComboBox (envfonts);
         fontlist.setSelectedIndex(0);
         fontlist.setEditable(true);
         fontlist.addActionListener(this);
         fontchoice = envfonts[0];     
    //Create a regular text field.
         JTextField textField = new JTextField(10);
         textField.setActionCommand(textFieldString);
         textField.addActionListener(this);
    public void actionPerformed(ActionEvent e) {
    //if the action is from the textfield (e.g. user hits enter)
         if (e.getActionCommand().equals(textFieldString)) {
              JTextField fromUser = (JTextField)e.getSource();
         if (fromUser != null){
    //place user text in editor pane
    //send message to server
                   if (userName.getText() != null) {
                        userString = userName.getText().trim();
                   out.println(userString + ": " + fromUser.getText());
              fromUser.setText("");
         else if (e.getActionCommand().equals(fontlist)){
         JComboBox cb = (JComboBox)e.getSource();
    String newSelection = (String)cb.getSelectedItem();
    currentFont = newSelection;
         userString = currentFont;
    return;

  • How to change background color in a window? Please help.

    Please help me to set background color to my window that includes some panels components.
    I have tried
    content.setBackground(Color.green); and
    frame.setBackground(Color.RED);
    but nothing works?
    Please what should I change in my code? Thanks already in advance for helping!!
    Main parts of my code:
    public void addComponentToPane(Container allComponents) throws IOException
    definePanels();
    allComponents.setLayout(new BoxLayout(allComponents, BoxLayout.Y_AXIS));
    allComponents.add(panel_introduction);
    allComponents.add(panel_n);
    allComponents.add(panel_resultTitle);
    allComponents.add(panel_w);
    allComponents.add(panel_testing);
    allComponents.setVisible(true);
    public static void main(String[] args) throws IOException
    try {
    GraphicsDevice device;
    Container content;
    JFrame frame = new JFrame("ImageOrder");
    device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    device.setFullScreenWindow(frame);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SwingApplication app = new SwingApplication();
    content = frame.getContentPane();
    content.setBackground(Color.green);
    app.addComponentToPane(content);
    frame.setVisible(true);
    finally {
    System.out.println("helle");
    }

    import java.awt.Color;
    import javax.swing.*;
    class Test extends JFrame {
         public Test( ){
              getContentPane().setBackground(Color.RED);
              pack();
              setSize(500, 500);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
         public static void main(String[] argv) {
              new Test().setVisible(true);
    }

  • Change the color of the text in textpane

    please suggest me how to change the color of the selected text color in textpane in jpanel
    class ComposeMailPanel extends JPanel implements ListSelectionListener, ActionListener, ItemListener
    JFrame frame;
    JTextPane jtextpane;
    JButton bInsertPic;
    JButton bBackgroundColor;
    JButton bForegroundColor;
    JFileChooser selectedFile;
    JFileChooser insertIconFile;
    JColorChooser backgroundChooser;
    JColorChooser foregroundChooser;
    JComboBox fontSize;
    SimpleAttributeSet sas;
    MutableAttributeSet sas1;
    StyleContext sc;
    DefaultStyledDocument dse;
    JScrollPane mainScrollPane;
    RTFEditorKit rtfkit;
    JComboBox fontFamily;
    MutableAttributeSet mas;
    Color backgroundColor;
    Color foregroundColor;
    String SF = "";
    public ComposeMailPanel()
         setLayout(null);
    bInsertPic = new JButton("Insert picture");
    add(bInsertPic);
    bInsertPic.setBounds(150,460,110,20);
    bInsertPic.setBackground(new Color(0,139,142));
    bInsertPic.setForeground(new Color(255,255,255) );
    bInsertPic.setBorder(borcolor);
    bInsertPic.addActionListener(this);
    bForegroundColor = new JButton("Set foreground color");
    add(bForegroundColor);
    bForegroundColor.setBounds(270,460,130,20);
    bForegroundColor.setBackground(new Color(0,139,142));
    bForegroundColor.setForeground(new Color(255,255,255) );
    bForegroundColor.setBorder(borcolor);
    bForegroundColor.addActionListener(this);
    fontFamily=new JComboBox();
    combofontfamilyinitialize();
    add(fontFamily);
    fontFamily.setBounds(420,460,110,20);
    fontFamily.setBackground(new Color(0,139,142));
    fontFamily.setForeground(new Color(255,255,255) );
    fontFamily.setBorder(borcolor);
    fontFamily.addItemListener(this);
    fontSize = new JComboBox();
    add(fontSize);
    fontSize.setBounds(550,460,40,20);
    fontSize.setBackground(new Color(0,139,142));
    fontSize.setForeground(new Color(255,255,255) );
    fontSize.setBorder(borcolor);
    fontSize.addItemListener(this);
    combofontsizeinitialize();
    sas = new SimpleAttributeSet();
    sas1 = new SimpleAttributeSet();
    sc = new StyleContext();
    dse = new DefaultStyledDocument(sc);
    rtfkit = new RTFEditorKit();
    selectedFile = new JFileChooser();
    insertIconFile = new JFileChooser();
    backgroundChooser = new JColorChooser();
    foregroundChooser = new JColorChooser();
         JScrollPane scrollPane2 = new JScrollPane();
         add(scrollPane2);
         scrollPane2.setBounds(150,300,577,152);
         jtextpane= new JTextPane();
         scrollPane2.getViewport().add(jtextpane);
         jtextpane.setBounds(150,300,572,150);
         jtextpane.setDocument(dse);
         jtextpane.setContentType( "text/html" );
         jtextpane.setEditable( true );
         jtextpane.setBackground(new Color(255,255,255));
         //jtextpane.setFont(new Font( "Serif", Font.PLAIN, 12 ));
         jtextpane.setForeground(new Color(0,0,0) );
         setBackground(new Color(0,139,142));
              }//constructor
    public void combofontfamilyinitialize ()
    GraphicsEnvironment ge1 = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] k = ge1.getAvailableFontFamilyNames();
    fontFamily= new JComboBox(k);
    public void combofontsizeinitialize ()
    //This function fills the combo box with font sizes
    fontSize.addItem("8");
    fontSize.addItem("9");
    fontSize.addItem("10");
    fontSize.addItem("11");
    fontSize.addItem("12");
    fontSize.addItem("14");
    public void setAttributeSet(AttributeSet attr)
    //This function only set the specified font set by the
    //attr variable to the text selected by the mouse
    int xStart, xFinish, k;
    xStart = jtextpane.getSelectionStart();
    xFinish = jtextpane.getSelectionEnd();
    k = xFinish - xStart;
    if(xStart != xFinish)
    dse.setCharacterAttributes(xStart, k, attr, false);
    else if(xStart == xFinish)
    //The below two command line updates the JTextPane according to what
    //font that is being selected at a particular moment
    mas = rtfkit.getInputAttributes();
    mas.addAttributes(attr);
    //The below command line sets the focus to the JTextPane
    jtextpane.grabFocus();
    public void actionPerformed(ActionEvent ae1)
    JComponent b = (JComponent)ae1.getSource();
    String str3 = null;
    frame = new JFrame();
    if(b == bInsertPic)
    System.out.println("inside insertpic");
    insertIconFile.setDialogType(JFileChooser.OPEN_DIALOG);
    insertIconFile.setDialogTitle("Select a picture to insert into document");
    if(insertIconFile.showDialog(frame,"Insert") != JFileChooser.APPROVE_OPTION)
    System.out.println("inside icon");
    return;
    File g = insertIconFile.getSelectedFile();
    ImageIcon image1 = new ImageIcon(g.toString());
    jtextpane.insertIcon(image1);
    jtextpane.grabFocus();
    else if(b == bForegroundColor)
              foregroundColor = foregroundChooser.showDialog(frame, "Color Chooser", Color.white);
    if(foregroundColor != null)
    String s1=jtextpane.getSelectedText();
         StyleConstants.setForeground(sas, foregroundColor);
    setAttributeSet(sas);
    public void itemStateChanged(ItemEvent ee5) {
    JComponent c = (JComponent)event.getSource();
    boolean d;
    if(c == fontFamily)
    String j = (String)fontFamily.getSelectedItem();
    StyleConstants.setFontFamily(sas, j);
    setAttributeSet(sas);
    else if(c == fontSize)
    String h = (String)fontSize.getSelectedItem();
    int r = Integer.parseInt(h);
    StyleConstants.setFontSize(sas, r);
    setAttributeSet(sas);
    thanks in advance

    Learn how to use the forum correctly by posting formatted code.
    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html]Text Component Features.

  • Someone knows how to change the font of a JTextField ?

    I tried almost everything, but I still can't change the Font of a JTextField...
    Thanks anyway...

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Testing extends JFrame
      JTextField tf = new JTextField("Hello World");
      public Testing()
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocation(400,300);
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fonts = ge.getAvailableFontFamilyNames();
        final JComboBox cbo = new JComboBox(fonts);
        getContentPane().add(tf,BorderLayout.NORTH);
        getContentPane().add(cbo,BorderLayout.SOUTH);
        pack();
        cbo.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            tf.setFont(new Font((String)cbo.getSelectedItem(),Font.PLAIN,12));}});
      public static void main(String args[]){new Testing().setVisible(true);}
    }

  • Changing cursor when rollover Jbutton

    hi All...i need help
    i want to change the cursor when i move my mouse over the button into hand cursor, then when the button being pressed, cursor change to Wait cursor
    here code of mine..
    import java.awt.Color;
    import java.awt.Cursor;
    import java.awt.GraphicsEnvironment;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    * @author tys
    public class cursor_test extends JFrame{
        public cursor_test(){                               
            add_panel panel = new add_panel();              
            add(panel);       
            setBackground(Color.WHITE);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            //GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
            setSize(200,200);
            setVisible(true);
            setTitle("Test cursor");
        public static void main(String[] args){
            new cursor_test();
        }//Main  
    }//end class frame
    class add_panel extends JPanel{
        public add_panel(){
            setLayout(null);
            JButton btn1 = new JButton("button");
            btn1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                      setCursor(new Cursor(Cursor.WAIT_CURSOR));                 
                      //do my program here
                      try{
                          Thread.sleep(1000);                     
                      catch(Exception z){};                                   
                      setCursor(new Cursor(Cursor.DEFAULT_CURSOR));                   
            });//emd ActionListener
            btn1.setSize(90, 30);
            btn1.setLocation(50, 40);
            btn1.setCursor(new Cursor(Cursor.HAND_CURSOR));       
            add(btn1);       
    }//end class panelwhat did i do wrong in there...because every time i pressed the button..the cursor still Hand Cursor
    Thx
    tys
    Edited by: KingMao on 22 Sep 08 19:35

    Hope this wll helps to you.
    class add_panel extends JPanel{
        public add_panel(){
            setLayout(null);
            final JButton btn1 = new JButton("button");
            btn1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                      *btn1.setCursor(new Cursor(Cursor.WAIT_CURSOR));*                 
                      //do my program here
                      try{
                          Thread.sleep(1000);
                          *btn1.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));*                    
                      catch(Exception z){};                                   
                      setCursor(new Cursor(Cursor.DEFAULT_CURSOR));                   
            });//emd ActionListener
            btn1.setSize(90, 30);
            btn1.setLocation(50, 40);
            btn1.setCursor(new Cursor(Cursor.HAND_CURSOR));       
            add(btn1);       
    }//end class panel

  • Java Screen Resolution Change

    sir i am using a jFrame container i want to make it full screen i am using following code for the full screen
    Declared as Global Variable boolean gridsize=false
    written in window State Change
    if(gridsize==true)
        gridsize=false;
       GraphicsDevice dev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
       GraphicsConfiguration gc = dev.getDefaultConfiguration();
       Dimension d=new Dimension();
      double x=d.getHeight();
    double y=d.getWidth();
    int height =(int)x;
    int width =(int)y;
    System.out.println("in"+gridsize);
      DisplayMode mode = new DisplayMode(height,width , 32, DisplayMode.REFRESH_RATE_UNKNOWN);
       //this.setSize(mode);
       dev.setFullScreenWindow(this);
    else if(gridsize==false)
        gridsize=true;
        System.out.println("out"+gridsize);
        this.setSize(700,700);
    }

    There are some components in a JFrame it is displaying in a full screen in the intiall resolution.
    if i change resolution the JFrame componets are not displayed correctly .

  • Changing screens

    How do I go about changing the screen of a swing GUI? I have two windows (not one large virtual window).
    I've been able to get the GraphicsConfiguration that I need (with a hardcoded device) and pop up an empty JFrame using that configuration. However, I'd like to switch the entire window over to the new screen, without having to rebuild the entire GUI (and therefore needing to reload all the data already visible).
    Also, how can I dynamically tell which screen the GUI is currently located on? I know there will always be two devices, and I'm using the following command to get both of them.
    GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()
    Right now I'm hardcoding the target to be either device 1 or 2, but I can't figure out how to decide that at runtime.
    Thanks for any help you can provide.
    -Adam

    double click the home button
    you'll see, the first one, a sqare with a round in it Press it
    Message was edited by: lll

  • Chat server change font tb

    I have created a chat server and have included a change font button where you can go in and select from the list of fonts colours and sizes and set them for the font to change.
    My question is can i get a list of fonts and colours to choose from or do I need to write them in an array string and somehow assign each one to the correct font/colour/size?
    Thanks

    I made you a small example:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test extends JFrame {
        private JComboBox faceBox;
        private JComboBox colourBox;
        private JComboBox sizeBox;
        private JLabel exampleLabel;
        public Test () {
            ActionListener actionListener = new ActionListener () {
                public void actionPerformed (ActionEvent event) {
                    updateExampleLabel ();
            faceBox = new JComboBox (getFaces ());
            faceBox.addActionListener (actionListener);
            colourBox = new JComboBox (getColours ());
            colourBox.addActionListener (actionListener);
            sizeBox = new JComboBox (getSizes ());
            sizeBox.addActionListener (actionListener);
            exampleLabel = new JLabel ();
            exampleLabel.setHorizontalAlignment (SwingConstants.CENTER);
            exampleLabel.setPreferredSize (new Dimension (400, 200));
            JPanel boxesPanel = new JPanel (new GridLayout (1, 3));
            boxesPanel.add (new TitledPanel (faceBox, "Font"));
            boxesPanel.add (new TitledPanel (colourBox, "Colour"));
            boxesPanel.add (new TitledPanel (sizeBox, "Size"));
            getContentPane ().setLayout (new BorderLayout ());
            getContentPane ().add (exampleLabel);
            getContentPane ().add (boxesPanel, BorderLayout.SOUTH);
            setDefaultCloseOperation (EXIT_ON_CLOSE);
            setTitle ("Font test");
            updateExampleLabel ();
            pack ();
            setLocationRelativeTo (null);
            show ();
        private Face[] getFaces () {
            Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment ().getAllFonts ();
            Face[] faces = new Face[fonts.length];
            for (int i = 0; i < faces.length; i ++) {
                faces[i] = new Face (fonts);
    return faces;
    private Colour[] getColours () {
    return new Colour[] {
    new Colour (Color.BLACK, "Black"),
    new Colour (Color.BLUE, "Blue"),
    new Colour (Color.GREEN, "Green"),
    new Colour (Color.ORANGE, "Orange"),
    new Colour (Color.RED, "Red"),
    new Colour (Color.WHITE, "White"),
    new Colour (Color.YELLOW, "Yellow")
    private Size[] getSizes () {
    int lower = 10;
    int upper = 36;
    Size[] sizes = new Size[(upper - lower) / 2 + 1];
    for (int i = 0; i < sizes.length; i ++) {
    sizes[i] = new Size (lower + i * 2);
    return sizes;
    private void updateExampleLabel () {
    Face face = (Face) faceBox.getSelectedItem ();
    Colour colour = (Colour) colourBox.getSelectedItem ();
    Size size = (Size) sizeBox.getSelectedItem ();
    exampleLabel.setText ("Font: " + face + ", colour: " + colour + ", size: " + size);
    exampleLabel.setFont (face.getFont ().deriveFont (size.getSize ()));
    exampleLabel.setForeground (colour.getColour ());
    private class Face {
    private Font font;
    public Face (Font font) {
    this.font = font;
    public Font getFont () {
    return font;
    public String toString () {
    return font.getName ();
    private class Colour {
    private Color colour;
    private String name;
    public Colour (Color colour, String name) {
    this.colour = colour;
    this.name = name;
    public Color getColour () {
    return colour;
    public String toString () {
    return name;
    private class Size {
    private float size;
    public Size (float size) {
    this.size = size;
    public float getSize () {
    return size;
    public String toString () {
    return String.valueOf ((int) size);
    private class TitledPanel extends JPanel {
    public TitledPanel (JComponent component, String title) {
    setBorder (BorderFactory.createTitledBorder (title));
    setLayout (new BorderLayout ());
    add (component);
    public static void main (String[] parameters) {
    new Test ();
    }Swing experts will slag me off because I'd rather create a class than set a renderer, but that's their problem, I suppose.
    Kind regards,
      Levi

  • BADI for changing fields during Creation of BP in CRM

    Hello to everyone,
      I need to find a BADI (or other way) to default several fields during BP creation in CRM (4.0 SR1 SP9). The fields I will like to set are TAX TYPE, TAX NUMBER, TAX CATEGORY, etc.. I have found the BADI BUPA_TAX_UPDATE but i dont see any suitable parameters (structures) to changes these fields. Please advice and thanks in advance.

    Hi
    If you use function BUPA_NUMBERS_GET then your BP number will already be buffered and you can avoid a DB read. It may also be that the BP is not in the DB yet anyway.
    You can only pass one GUID in at a time - loop through IT_CHANGED_INSTANCES into a variable of type BU_PARTNER_GUID and pass that into the function as input parameter IV_PARTNER_GUID.
    Cheers
    Dom

  • How to restrict manual changing of free goods in sales order

    Hi ,
    Goodmorning ,
    We have some requirement : In sales order free goods quantity determination by system  should not be allowed to change manually , where can we do this ?
    Looking for your inputs
    Thanks and regards
    Venkat

    As per SAP Standard, when the main Item quantity is changed, the Free Goods are redetermined. In this case any manual changes to Free Goods Quantities are lost.
    But your requirement is for restricting the Chages of the Quantity of Free Goods Correct?
    I believe there is no SAP standard solution for this. You will have to apply a User Exit, which will check the Item category of each LIne item & if it is free goods (TANN) then changes are not permitted.
    Hope this helps.
    Thanks,
    Jignesh Mehta

  • Sy-tabix value has changed...

    Hi Gurus,
    I  am using a code like dis...this is not the actual code m using instad m sendin u a sample program so that u can understand the problem
    There is a selecvtion for Customer.
    sort itab by kunnr.
    loop at itab.
    on change of itab-kunnr.
    wkunnr = itab-kunnr.
      read table zitab with key kunnr = itab-kunnr.
    endon.
    if itab-kunnr = wkunnr.
    wdmbtr = wdmbtr + itab-dmbtr.
    endif.
    at end of kunnr.
    ftab-kunnr = wkunnr.
    ftab-dmbtr = wdmbtr.
    append ftab.
    endat.
    endloop.
    Now my problem is that  AT END OF Kunnr is working fine for the first customer or say for single customer but when there are multiple customers  AT END OF kunnr is triggring for each entry.......
    In debug MOdei can see that as soon as read table  syntax is used the tabix value is changed....
    So Can anyone suggest what is the solution....
    Regards,
    Raman

    This is the Declaration
    DATA:  BEGIN OF ITAB OCCURS 0,
                      KUNNR      LIKE BSID-KUNNR,
                      BELNR      LIKE BSID-BELNR,
                      BUKRS      LIKE BSID-BUKRS,
                      GJAHR      LIKE BSID-GJAHR,
                      BUZEI      LIKE BSID-BUZEI,
                      SHKZG      LIKE BSID-SHKZG,
                      VALUT      LIKE BSID-ZFBDT,
                      SGTXT(70)  TYPE  C,
                      ZFBDT      LIKE BSID-ZFBDT,
                      ZBD1T       TYPE BSID-ZBD1T,
           ZBD2T       TYPE BSID-ZBD2T,
           ZBD3T       TYPE BSID-ZBD3T,
           REBZG       TYPE BSID-REBZG,
           NETDT       TYPE BSID-BUDAT,
                      ZUONR      LIKE BSID-ZUONR,
                       BLART      LIKE BSID-BLART,
                      DMBTR      LIKE BSID-DMBTR,
                      SPART       TYPE VBRK-SPART,
                      DAY    TYPE RFPOSX-VERZN,
                      FLAG TYPE C,
                      CITY        TYPE KNA1-ORT01,
           NAME1       TYPE LFA1-NAME1,
                     CR_DR1(4)  TYPE C,
                      PSWSL      LIKE BSID-PSWSL,
                      ZTERM      LIKE BSID-ZTERM,
                      VBELN      LIKE BSID-VBELN,
                      UMSKZ      LIKE BSID-UMSKZ,
                      KLIMK      LIKE KNKK-KLIMK,
                      VTEXT      LIKE TVZBT-VTEXT,
                      ADV        LIKE BSID-DMBTR,
                      REBZT       TYPE BSID-REBZT,
                      XBLNR      LIKE BSID-XBLNR,
                      VTEXT1(70) TYPE  C,
                       FKLIMK    LIKE KNKK-KLIMK,
                      ABC(4)     TYPE C,
                    AGRO(4)        TYPE C,
                      BIO(4)        TYPE C,
                      SKFOR      LIKE KNKK-SKFOR,
                      SSOBL      LIKE KNKK-SSOBL,
                      CTLPC      LIKE KNKK-CTLPC,
                      OEIKW      LIKE S066-OEIKW,
                      OLIKW      LIKE S067-OLIKW,
                      OFAKW      LIKE S067-OFAKW,
                     NAME1      LIKE LFA1-NAME1,
                      BUDAT      LIKE BKPF-BUDAT,
                      D_DMBTR    LIKE BSID-DMBTR,
                      S_DMBTR    LIKE BSID-DMBTR,
                      VORGN      LIKE BSEG-VORGN,
                      WERKS      LIKE BSEG-WERKS,
                      NAMESO     LIKE KNA1-NAME1,
                      NAMEAM     LIKE KNA1-NAME1,
                      NAMERM     LIKE KNA1-NAME1,
                       NAMEDR     LIKE KNA1-NAME1,
       END OF ITAB.

  • ANY SY-INDEX REFLECT CHANGES WHEN CONTROL BREAK STATEMENT PROCESS

    Dear Guru's,
                     I have a requirement where i have to move the values to variable when control break (AT END OF) process. So i want to move the values according to the end of Vendor so for that  i want to know is there any sy-index available which reflects changes when Control break (AT end of) process.
    LIKE Sy-subrc = 0 when select statement fetches record or sy-tabix is like counter for loop.
    Hope to get reply soon.
    Regards,
    Himanshu Rangappa

    Hi,
    There is no system Fields for it.
    But your requirement can be done with 'AT NEW' and 'AT END' statement.
    Refer this sample example,
    loop at otab.
        at new module.
          move otab-module to otab2-module.
        ENDAT.
          at END OF effort.
          sum.               "Do your calculations here
          move otab-count to otab2-count.
          append otab2.
        endat.
      endloop.

  • How to change SSO Partner Application Login_url and Logout_url

    As part of a deployment in a different data centre, we needed to change the domain name of an application using SSO for authentication. We have gone through the process of re-registering the SSO server but this does not update the domain name
    By using diagnostic tools from Oracle we have discovered that the file 'osso.conf' in $ORACLE_HOME/Apache/Apache/conf/osso contains incorrect entries for login_url and logout_url.
    These settings are of the form:
    login_url=http://www.ourolddomain.com/pls/orasso/orasso.wwsso_app_admin.ls_login
    logout_url=http://www.ourolddomain.com/pls/orasso/orasso.wwsso_app_admin.ls_logout
    Please can anyone tell me how these settings can be changed.

    Hi,
    [Solved] SSO fails to show success page you can find some information on re registering mod_osso.
    Hope it helps.

Maybe you are looking for