JButton in side JTabe

Hi all,
i created JTable & put JButton column inside it by using the cell editor & cell render, but the code of the actionPerformed method of the jbutton is not executed.
the following is the code for cell editor
public class ButtonEditor extends DefaultCellEditor {
protected JButton button;
String label;
boolean isPushed;
public ButtonEditor(JCheckBox checkBox) {
super(checkBox);
button = new JButton();
//button.setOpaque(true);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//open the current file
//fireEditingStopped();
//button.setText("Yarb");
System.out.println("Yarab");
any help please

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
public class Main /**extends DefaultCellEditor**/ {
    protected JButton button;
    String label;
    boolean isPushed;
    public Main() {
    //super(checkBox);
    button = new JButton();
    //button.setOpaque(true);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //open the current file
            //fireEditingStopped();
            //button.setText("Yarb");
            System.out.println("Yarab");
    public static void main(String[] args )
        Main m = new Main();
}I think I would need to see more of your code to fix the problem.

Similar Messages

  • Add button to JTabbedPane to add new tab

    Does anyone know how to add a JButton to a JTabbed pane (in the tab bar) so that it is always at the end of all the tabs and when it is clicked it will add a new tab into the tabbed pane.
    The functionallity I am looking for is the same as that provided by the button in the tab bar for Firefox and Internet Explorer.

    Along the line of what TBM was saying:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    class NewTabDemo implements Runnable
      JTabbedPane tabs;
      ChangeListener listener;
      int numTabs;
      public static void main(String[] args)
        SwingUtilities.invokeLater(new NewTabDemo());
      public void run()
        listener = new ChangeListener()
          public void stateChanged(ChangeEvent e)
            addNewTab();
        tabs = new JTabbedPane();
        tabs.add(new JPanel(), "Tab " + String.valueOf(numTabs), numTabs++);
        tabs.add(new JPanel(), "+", numTabs++);
        tabs.addChangeListener(listener);
        JFrame frame = new JFrame(this.getClass().getName());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(tabs, BorderLayout.CENTER);
        frame.pack();
        frame.setSize(new Dimension(400,200));
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      private void addNewTab()
        int index = numTabs-1;
        if (tabs.getSelectedIndex() == index)
          tabs.add(new JPanel(), "Tab " + String.valueOf(index), index);
          tabs.removeChangeListener(listener);
          tabs.setSelectedIndex(index);
          tabs.addChangeListener(listener);
          numTabs++;
    }

  • Next-gen Applet is completely blank on Mac OS X

    Hi.
    I am experiencing a strange behavior on Mac OS X with Java Applets deployed though the JNLP mechanism (i.e., exploiting the next-generation Java Plug-in).
    For testing purposes, I have developed a VERY SIMPLE applet, just setting a BorderLayout on JApplet's contentPane, then adding sample JButtons on sides, and a sample JLabel in the center. Here is the code:
    ====
    import java.awt.BorderLayout;
    import javax.swing.*;
    public class TestApplet extends JApplet
    public void init()
    uiInit();
    // TODO overwrite start(), stop() and destroy() methods
    private void uiInit()
    try
    SwingUtilities.invokeAndWait(new Runnable()
    public void run()
    JButton northButton = new JButton("North button");
    JButton southButton = new JButton("South button");
    JButton eastButton = new JButton("East button");
    JButton westButton = new JButton("West button");
    JLabel centerLabel = new JLabel("Center label");
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(northButton, BorderLayout.NORTH);
    getContentPane().add(southButton, BorderLayout.SOUTH);
    getContentPane().add(eastButton, BorderLayout.EAST);
    getContentPane().add(westButton, BorderLayout.WEST);
    getContentPane().add(centerLabel, BorderLayout.CENTER);
    catch (Exception ex)
    // It's OK
    ====
    While this simple Applet works fine on Windows clients running a recent JRE, it displays NOTHING on recent Mac OS X clients (tested on both Mac OS X 10.7 and 10.8).
    You can test this Applet yourself at:
    http://67.225.240.233/TestApplet/TestApplet.htm
    Can some Mac users check if they obtain a blank screen on their Mac OS X clients as well?
    Can someone guess why I am obtaining this behavior? A bug of Apple's implementation? If yes, it would be a really SERIOUS bug...
    It is important to notice that this same applet displays fine on Mac if using the "old fashioned" <applet> tag (i.e., no JNLP).
    Any feedback or hint would be greatly appreciated.
    Thanks and best regards,
    Marco

    Thank you. That helps a lot. Since update 9 seemed to cause problems with webstart I had been focusing on trying different methods to start it. It never occurred to me to try changing the size. Although with a smaller size I'm still getting random graphics artifacts(short red lines and dots through out as well as combo boxes that don't show up and tabs where the text shows but not the tab), but it still requires scrolling so I'll try opening it in a page by itself to avoid any scrolling and see if it looks more normal. This applet is using double buffering because its drawing genes, heat maps, sequences that users can zoom in and out and navigate so it just didn't look great without double buffering.
    Everything that you describe seems to fit with what I'm seeing. Thank you for figuring it out and submitting a bug report. I hope they'll fix it soon.

  • JButtons in JToolbar don't work with JApplet- why?

    I made a JApplet which has a toolbar, populated with burrons that manipulate data from text files. The programs works perfectly when it is not a JApplet. However, once I converted it to a JApplet it does nothing. The code was exactly the same, but, pressing buttons does nothing when it is an applet. here is the complete code;
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    public class CSE extends JApplet implements ActionListener, ItemListener
    //GUI COMPONENTS
    //ToolBar components
    JToolBar mainSelect = new JToolBar("Materials");
    JButton materials;
    String materialNames[] = {"Fur Square", "Bolt of Linen", "Bolt of Damask", "Bolt of Silk", "Glob of Ectoplasm", "Steel Ingot", "Deldrimor Steel Ingot", "Monstrous Claw", "Monstrous Eye", "Monstrous Fang", "Ruby", "Lump of Charcoal", "Obsidian Shard", "Tempered Glass Vial", "Leather Square", "Elonian Leather Square", "Vial of Ink", "Roll of Parchment", "Roll of Vellum", "Spiritwood Plank", "Amber Chunk", "Jadeite Shard"};
    ImageIcon materialIcons;
    //Graphic components
    JDesktopPane mainGraph = new JDesktopPane();
    JPanel dailyGraph = new JPanel();
    JPanel weeklyGraph = new JPanel();
    JPanel finalPrices = new JPanel();
    Box graphs = Box.createHorizontalBox();
    //The Console
    JFrame CSEFrame = new JFrame();
    JSplitPane mainConsoleBackdrop = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    JSplitPane dataOut = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    JTextArea prediction = new JTextArea(10,10);
    JScrollPane predictionScroll;
    Box finalPricesLabels = Box.createVerticalBox();
    Box finalPricesLay = Box.createVerticalBox();
    JLabel finalBuy = new JLabel("Net Buy Price Change: 0.00");
    JLabel finalSell = new JLabel("Net Sell Price Change: 0.00");
    JLabel buySell = new JLabel("We recommend you: N/A");
    JTextArea priceUpdate = new JTextArea(10, 10);
    JTextArea priceUpdateWeekly = new JTextArea(10, 10);
    JScrollPane priceUScrollW;
    JScrollPane priceUScroll;
    JCheckBox weeklySelect = new JCheckBox("To show weekly price changes.", false);
    JCheckBox dailySelect = new JCheckBox("To show daily price changes.", true);
    ButtonGroup dataToShow = new ButtonGroup();
    //COMPONENTS FOR DATE; OBTAINING CORRECT FOLDER
    String days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
    Calendar calSource = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    int day = calSource.get(Calendar.DAY_OF_MONTH);
    int month = calSource.get(Calendar.MONTH);
    int year = calSource.get(Calendar.YEAR);
    int monthCheck [] = {Calendar.JANUARY, Calendar.FEBRUARY, Calendar.MARCH, Calendar.APRIL, Calendar.MAY, Calendar.JUNE, Calendar.JULY, Calendar.AUGUST, Calendar.SEPTEMBER, Calendar.OCTOBER, Calendar.NOVEMBER, Calendar.DECEMBER};
    int dayS = day;
    int monthS = month;
    int yearS = year;
    //if there is file found
    boolean proceed = false;
    //int data for analysis
    int buyPrice;
    int currentBuyPrice;
    int sellPrice;
    int currentSellPrice;
    boolean weekly = false;
    //tools for parsing and decoding input
    String inputS = null;
    String s = null;
    Scanner [] week = new Scanner[7];
    Scanner scanner;
    int position = 0;
    //weekly tools
    String weekPos[] = {"Seventh", "Sixth", "Fifth", "Fourth", "Third", "Second", "First"};
    int dayOfWeek = 0; //0 = 7    1 = 6...
                    public JButton getToolBarButton(String s)
                        String imgLoc = "TBar Icons/" +s +".gif";
                        java.net.URL imgURL = CSE.class.getResource(imgLoc);
                        JButton button = new JButton();
                        button.setActionCommand(s);
                        button.setToolTipText(s);
                        button.addActionListener(this);
                        if(imgURL != null)
                            button.setIcon(new ImageIcon(imgURL, s));
                        else
                            button.setText(s);
                            System.err.println("Couldn't find; " +imgLoc);
                        return button;
                        public CSE()
                                   // super("Test CSE");
                                    //CSEFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                    for(int x=0; x<materialNames.length; x++)
                                        materials = getToolBarButton(materialNames[x]);
                                        mainSelect.add(materials);
                                    //checkBoxes
                                    dataToShow.add(weeklySelect);
                                    dataToShow.add(dailySelect);
                                    weeklySelect.addItemListener(this);
                                    dailySelect.addItemListener(this);
                                    // sizes
                                    setSize(850, 850);
                                    //colors and fonts
                                    weeklyGraph.setBackground(new Color(250, 30, 40));
                                    dailyGraph.setBackground(new Color(100, 40, 200));
                                    //text Manip.
                                    prediction.setLineWrap(true);
                                    priceUpdate.setLineWrap(true);
                                    //scrolling
                                    predictionScroll = new JScrollPane(prediction, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                    priceUScroll = new JScrollPane(priceUpdate, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                    priceUScrollW = new JScrollPane(priceUpdateWeekly, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                                    //main splitpane config.
                                    mainConsoleBackdrop.setOneTouchExpandable(true);
                                    mainConsoleBackdrop.setResizeWeight(.85);
                                    //placement and Layout
                                    //GraphLayout
                                    graphs.add(Box.createHorizontalStrut(10));
                                    graphs.add(dailyGraph);
                                    graphs.add(Box.createHorizontalStrut(10));
                                    graphs.add(weeklyGraph);
                                    graphs.add(Box.createHorizontalStrut(10));
                                    dataOut.setRightComponent(predictionScroll);
                                    //consoleData layout
                                    finalPricesLabels.add(Box.createVerticalStrut(10));
                                    finalPricesLabels.add(finalBuy);
                                    finalPricesLabels.add(Box.createVerticalStrut(10));
                                    finalPricesLabels.add(finalSell);
                                    finalPricesLabels.add(Box.createVerticalStrut(10));
                                    finalPricesLabels.add(buySell);
                                    finalPricesLay.add(finalPricesLabels);
                                    finalPricesLay.add(Box.createVerticalStrut(10));
                                    finalPricesLay.add(weeklySelect);
                                    finalPricesLay.add(dailySelect);
                                    finalPricesLay.add(priceUScroll);
                                    dataOut.setLeftComponent(finalPricesLay);
                                    mainConsoleBackdrop.setTopComponent(graphs);
                                    mainConsoleBackdrop.setBottomComponent(dataOut);
                                    getContentPane().add(mainConsoleBackdrop);
                                    getContentPane().add(mainSelect, BorderLayout.NORTH);
                                    //visibility
                                   // CSEFrame.setVisible(true);
                                    //return(CSEFrame);
                                        public void actionPerformed(ActionEvent e)
                                            getMonth();
                                            inputS = e.getActionCommand();
                                            FileReader newRead = null;
                                                    try {
                                                           newRead = new FileReader(monthS +"-" +dayS +"-" +yearS +"/" +inputS +".dat");
                                                           proceed = true;
                                                        catch(FileNotFoundException f)
                                                           System.out.println("File not found");
                                                           proceed = false;
                                          if(proceed)
                                          BufferedReader bufferedReader = new BufferedReader(newRead);
                                          scanner  = new Scanner(bufferedReader);
                                          scanner.useDelimiter("\n");
                                         //starts daily analysis
                                          getPrice(scanner);
                                        //starts weekly analysis
                                          weekly(inputS);
                                    public void itemStateChanged(ItemEvent e)
                                        if(weeklySelect.isSelected())
                                        priceUpdateWeekly.setText("");
                                        finalPricesLay.remove(priceUScroll);
                                        finalPricesLay.add(priceUScrollW);
                                        finalPrices.updateUI();
                                        else
                                            priceUpdate.setText("");
                                            finalPricesLay.remove(priceUScrollW);
                                            finalPricesLay.add(priceUScroll);
                                            finalPrices.updateUI();
                                    public void weekly(String inputS)
                                        weekly = true;
                                        for(int x = 0; x < 7; x++)
                                           dateToUse(month, day, year, (x+1));
                                            try
                                                    FileReader weeklySource = new FileReader(monthS +"-" +dayS +"-" +year +"/" +inputS +".dat");
                                                    BufferedReader weeklyBuffer = new BufferedReader(weeklySource);
                                                    week[x] = new Scanner(weeklyBuffer);
                                                    week[x].useDelimiter("\n");
                                                    getPrice(week[x]);
                                             catch(FileNotFoundException f)
                                                JOptionPane.showMessageDialog(this, "No such weekly files- going back;" +(x+1) +"days");
                                        weekly = false;
                                        dateReset();
                                    public void getPrice(Scanner scanner)
                                        while(scanner.hasNextLine())
                                            //puts into string the next scan token
                                            String s = scanner.next();
                                            //takes the scan toke above and puts it into an editable enviroment
                                            String [] data = s.split("\\s");
                                            for(position = 0; position < data.length; position++)
                                                        //Scanner test to make sure loop can finish, otherwise "no such line" error
                                                        if(scanner.hasNextLine()==false)
                                                        scanner.close();
                                                        break;
                                                           /*Starts data orignazation by reading from each perspective field
                                                            * 1 = day
                                                            * 2 = day of month
                                                            * 3 = month
                                                            * 4 = year
                                                           if(position == 0 && weekly == false)
                                                               String dayFromFile = data[position];
                                                                int dayNum = Integer.parseInt(dayFromFile);
                                                              priceUpdate.append(days[dayNum-1] +" ");
                                                           else if(position == 1  && weekly == false )
                                                              priceUpdate.append(data[position] + "/");
                                                           else if(position == 2 && weekly == false)
                                                              priceUpdate.append(data[position] + "/");
                                                            else if(position == 3 && weekly == false)
                                                                priceUpdate.append(data[position] +"\n");
                                                           //if it is in [buy] area, it prints and computes
                                                            else if(position == 7)
                                                                //obtains string for buy price and stores it, then prints it
                                                                String buy = data[position];
                                                            if(weekly == false)
                                                            priceUpdate.append("Buy: " +buy +"\n" );
                                                             //converts buy to string
                                                            currentBuyPrice = Integer.parseInt(buy);
                                                            //eliminates problems caused by no data from server- makes the price 0
                                                            if(currentBuyPrice < 0)
                                                                currentBuyPrice = 0;
                                                            //if it is greater it adds
                                                            if(currentBuyPrice > buyPrice)
                                                                     buyPrice += currentBuyPrice;
                                                            //if it is equal [there is no change] then it does nothing    
                                                            if(currentBuyPrice == buyPrice)
                                                                buyPrice +=0;
                                                            //if there is a drop, it subtracts
                                                               else
                                                                   buyPrice -= currentBuyPrice;
                                                            //if it is in [sell] area, it prints, and resets the position to zero because line is over
                                                            else if(position == 8)
                                                                //puts sell data into string and prints it
                                                                String sell = data[position];
                                                                if(weekly == false)
                                                                priceUpdate.append("Sell: " + sell +"\n");
                                                                //turns sell data into int.
                                                              currentSellPrice = Integer.valueOf(sell).intValue();;
                                                            //gets rid of problems caused by no data on server side- makes it 0 
                                                            if(currentSellPrice < 0)
                                                                currentSellPrice = 0;
                                                            //adds if there is an increase
                                                            if(currentSellPrice > sellPrice)
                                                                     sellPrice += currentSellPrice;
                                                            //does nothing if it is the same    
                                                            if(currentSellPrice == sellPrice)
                                                                sellPrice +=0;
                                                            //subtracts if there is drop
                                                               else
                                                                   sellPrice -= currentSellPrice;
                                                                //further protection against "No such line" and moves it down
                                                               if(scanner.hasNextLine() == true)
                                                                scanner.nextLine();
                                                                //if scanner is finished, prints out all lines
                                                               if(scanner.hasNextLine() == false && weekly == false)
                                                                finalBuy.setText("Net Buy Price Change: "+buyPrice);
                                                                finalSell.setText("Net Sell Price Change: " +sellPrice);
                                                                buyPrice = 0;
                                                                sellPrice = 0;
                                                                position = data.length;
                                                               else if(scanner.hasNextLine() == false && weekly == true)
                                                                   priceUpdateWeekly.append("\n" +weekPos[dayOfWeek] +" day of the week ended with; \nBuy Price;" +buyPrice +"\nSell Price;" +sellPrice);
                                                                   buyPrice = 0;
                                                                   sellPrice = 0;
                                                                   position = data.length;
                                                                   dayOfWeek++;
                                                                   if(dayOfWeek > 6)
                                                                   dayOfWeek = 0;
                                public void getMonth()
                                    for(int x=0; x < monthCheck.length; x++)
                                        if(month == monthCheck[x])
                                              monthS = (x+1);
                                              x = monthCheck.length;
                                 public void dateToUse(int month, int day, int year, int increment)
                                 //set day of source
                                  dayS = (day - increment);
                                //if day of source is less then O then we have moved to another month 
                                if(dayS <= 0)
                                        //checks the difference between how much we have incremented and the day we have started; this tells us how far into the new month we are
                                        int incrementDay = increment - day;
                                        //decrements month
                                        monthS--;
                                        //if month is less then zero, then we have moved into another year and month has become 12
                                        if(monthS <= 0)
                                            yearS--;
                                            monthS = 12;
                                        //the following looks at the current month and if it goes below it assigns the day to the proper ammount of days of the month before minus the days into the month
                                           if(month == 3)
                                               dayS = 28 - incrementDay;
                                           else if(month == 5 || month == 7)
                                               dayS = 29 - incrementDay;
                                           else if(month == 2 || month == 4 || month == 6 || month == 9 || month == 11)
                                               dayS = 31 - incrementDay;
                                            else
                                                dayS = 30 - incrementDay;
                               //resets the source date to the current date once data from the week has been reached
                                public void dateReset()
                                    dayS = day;
                                    monthS = month;
                                    yearS = year;
                     public void init()
                         //JFrame frame = new CSEFrameSet();
                        // this.setContentPane(CSEFrameSet());
                        CSE aCSE = new CSE();
    public static void main(String [] args)
    CSE cs = new CSE();
    }I have tried uploading it to a server, running it from appletviewer, and locally using the .HTML file. The GUI works fine, everything is there, however, pressing the buttons does nothing.
    Can you not use the Scanners and such with JApplets?
    Yes, the directories are good.
    EDIT EDIT EDIT; OK, it works with appletviewer, but still doesn't work when it is published.
    Message wa

    I can't seem to edit the post anymore, here it is again;
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    public class CSE extends JApplet implements ActionListener, ItemListener
    //GUI COMPONENTS
    //ToolBar components
    JToolBar mainSelect = new JToolBar("Materials");
    JButton materials;
    String materialNames[] = {"Fur Square", "Bolt of Linen", "Bolt of Damask", "Bolt of Silk", "Glob of Ectoplasm", "Steel Ingot", "Deldrimor Steel Ingot", "Monstrous Claw", "Monstrous Eye", "Monstrous Fang", "Ruby", "Lump of Charcoal", "Obsidian Shard", "Tempered Glass Vial", "Leather Square", "Elonian Leather Square", "Vial of Ink", "Roll of Parchment", "Roll of Vellum", "Spiritwood Plank", "Amber Chunk", "Jadeite Shard"};
    ImageIcon materialIcons;
    //Graphic components
    JDesktopPane mainGraph = new JDesktopPane();
    JPanel dailyGraph = new JPanel();
    JPanel weeklyGraph = new JPanel();
    JPanel finalPrices = new JPanel();
    Box graphs = Box.createHorizontalBox();
    //The Console
    JFrame CSEFrame = new JFrame();
    JSplitPane mainConsoleBackdrop = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    JSplitPane dataOut = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    JTextArea prediction = new JTextArea(10,10);
    JScrollPane predictionScroll;
    Box finalPricesLabels = Box.createVerticalBox();
    Box finalPricesLay = Box.createVerticalBox();
    JLabel finalBuy = new JLabel("Net Buy Price Change: 0.00");
    JLabel finalSell = new JLabel("Net Sell Price Change: 0.00");
    JLabel buySell = new JLabel("We recommend you: N/A");
    JTextArea priceUpdate = new JTextArea(10, 10);
    JTextArea priceUpdateWeekly = new JTextArea(10, 10);
    JScrollPane priceUScrollW;
    JScrollPane priceUScroll;
    JCheckBox weeklySelect = new JCheckBox("To show weekly price changes.", false);
    JCheckBox dailySelect = new JCheckBox("To show daily price changes.", true);
    ButtonGroup dataToShow = new ButtonGroup();
    //COMPONENTS FOR DATE; OBTAINING CORRECT FOLDER
    String days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
    Calendar calSource = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    int day = calSource.get(Calendar.DAY_OF_MONTH);
    int month = calSource.get(Calendar.MONTH);
    int year = calSource.get(Calendar.YEAR);
    int monthCheck [] = {Calendar.JANUARY, Calendar.FEBRUARY, Calendar.MARCH, Calendar.APRIL, Calendar.MAY, Calendar.JUNE, Calendar.JULY, Calendar.AUGUST, Calendar.SEPTEMBER, Calendar.OCTOBER, Calendar.NOVEMBER, Calendar.DECEMBER};
    int dayS = day;
    int monthS = month;
    int yearS = year;
    //if there is file found
    boolean proceed = false;
    //int data for analysis
    int buyPrice;
    int currentBuyPrice;
    int sellPrice;
    int currentSellPrice;
    boolean weekly = false;
    //tools for parsing and decoding input
    String inputS = null;
    String s = null;
    Scanner [] week = new Scanner[7];
    Scanner scanner;
    int position = 0;
    //weekly tools
    String weekPos[] = {"Seventh", "Sixth", "Fifth", "Fourth", "Third", "Second", "First"};
    int dayOfWeek = 0; //0 = 7 1 = 6...
    public JButton getToolBarButton(String s)
    String imgLoc = "TBar Icons/" +s +".gif";
    java.net.URL imgURL = CSE.class.getResource(imgLoc);
    JButton button = new JButton();
    button.setActionCommand(s);
    button.setToolTipText(s);
    button.addActionListener(this);
    if(imgURL != null)
    button.setIcon(new ImageIcon(imgURL, s));
    else
    button.setText(s);
    System.err.println("Couldn't find; " +imgLoc);
    return button;
    public CSE()
    // super("Test CSE");
    //CSEFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    for(int x=0; x<materialNames.length; x++)
    materials = getToolBarButton(materialNames[x]);
    mainSelect.add(materials);
    //checkBoxes
    dataToShow.add(weeklySelect);
    dataToShow.add(dailySelect);
    weeklySelect.addItemListener(this);
    dailySelect.addItemListener(this);
    // sizes
    setSize(850, 850);
    //colors and fonts
    weeklyGraph.setBackground(new Color(250, 30, 40));
    dailyGraph.setBackground(new Color(100, 40, 200));
    //text Manip.
    prediction.setLineWrap(true);
    priceUpdate.setLineWrap(true);
    //scrolling
    predictionScroll = new JScrollPane(prediction, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    priceUScroll = new JScrollPane(priceUpdate, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    priceUScrollW = new JScrollPane(priceUpdateWeekly, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    //main splitpane config.
    mainConsoleBackdrop.setOneTouchExpandable(true);
    mainConsoleBackdrop.setResizeWeight(.85);
    //placement and Layout
    //GraphLayout
    graphs.add(Box.createHorizontalStrut(10));
    graphs.add(dailyGraph);
    graphs.add(Box.createHorizontalStrut(10));
    graphs.add(weeklyGraph);
    graphs.add(Box.createHorizontalStrut(10));
    dataOut.setRightComponent(predictionScroll);
    //consoleData layout
    finalPricesLabels.add(Box.createVerticalStrut(10));
    finalPricesLabels.add(finalBuy);
    finalPricesLabels.add(Box.createVerticalStrut(10));
    finalPricesLabels.add(finalSell);
    finalPricesLabels.add(Box.createVerticalStrut(10));
    finalPricesLabels.add(buySell);
    finalPricesLay.add(finalPricesLabels);
    finalPricesLay.add(Box.createVerticalStrut(10));
    finalPricesLay.add(weeklySelect);
    finalPricesLay.add(dailySelect);
    finalPricesLay.add(priceUScroll);
    dataOut.setLeftComponent(finalPricesLay);
    mainConsoleBackdrop.setTopComponent(graphs);
    mainConsoleBackdrop.setBottomComponent(dataOut);
    getContentPane().add(mainConsoleBackdrop);
    getContentPane().add(mainSelect, BorderLayout.NORTH);
    //visibility
    // CSEFrame.setVisible(true);
    //return(CSEFrame);
    public void actionPerformed(ActionEvent e)
    getMonth();
    inputS = e.getActionCommand();
    FileReader newRead = null;
    try {
    newRead = new FileReader(monthS +"-" +dayS +"-" +yearS +"/" +inputS +".dat");
    proceed = true;
    catch(FileNotFoundException f)
    System.out.println("File not found");
    proceed = false;
    if(proceed)
    BufferedReader bufferedReader = new BufferedReader(newRead);
    scanner = new Scanner(bufferedReader);
    scanner.useDelimiter("\n");
    //starts daily analysis
    getPrice(scanner);
    //starts weekly analysis
    weekly(inputS);
    public void itemStateChanged(ItemEvent e)
    if(weeklySelect.isSelected())
    priceUpdateWeekly.setText("");
    finalPricesLay.remove(priceUScroll);
    finalPricesLay.add(priceUScrollW);
    finalPrices.updateUI();
    else
    priceUpdate.setText("");
    finalPricesLay.remove(priceUScrollW);
    finalPricesLay.add(priceUScroll);
    finalPrices.updateUI();
    public void weekly(String inputS)
    weekly = true;
    for(int x = 0; x >< 7; x++)
    dateToUse(month, day, year, (x+1));
    try
    FileReader weeklySource = new FileReader(monthS +"-" +dayS +"-" +year +"/" +inputS +".dat");
    BufferedReader weeklyBuffer = new BufferedReader(weeklySource);
    week[x] = new Scanner(weeklyBuffer);
    week[x].useDelimiter("\n");
    getPrice(week[x]);
    catch(FileNotFoundException f)
    JOptionPane.showMessageDialog(this, "No such weekly files- going back;" +(x+1) +"days");
    weekly = false;
    dateReset();
    public void getPrice(Scanner scanner)
    while(scanner.hasNextLine())
    //puts into string the next scan token
    String s = scanner.next();
    //takes the scan toke above and puts it into an editable enviroment
    String [] data = s.split("\\s");
    for(position = 0; position < data.length; position++)
    //Scanner test to make sure loop can finish, otherwise "no such line" error
    if(scanner.hasNextLine()==false)
    scanner.close();
    break;
    /*Starts data orignazation by reading from each perspective field
    * 1 = day
    * 2 = day of month
    * 3 = month
    * 4 = year
    if(position == 0 && weekly == false)
    String dayFromFile = data[position];
    int dayNum = Integer.parseInt(dayFromFile);
    priceUpdate.append(days[dayNum-1] +" ");
    else if(position == 1 && weekly == false )
    priceUpdate.append(data[position] + "/");
    else if(position == 2 && weekly == false)
    priceUpdate.append(data[position] + "/");
    else if(position == 3 && weekly == false)
    priceUpdate.append(data[position] +"\n");
    //if it is in [buy] area, it prints and computes
    else if(position == 7)
    //obtains string for buy price and stores it, then prints it
    String buy = data[position];
    if(weekly == false)
    priceUpdate.append("Buy: " +buy +"\n" );
    //converts buy to string
    currentBuyPrice = Integer.parseInt(buy);
    //eliminates problems caused by no data from server- makes the price 0
    if(currentBuyPrice < 0)
    currentBuyPrice = 0;
    //if it is greater it adds
    if(currentBuyPrice > buyPrice)
    buyPrice += currentBuyPrice;
    //if it is equal [there is no change] then it does nothing
    if(currentBuyPrice == buyPrice)
    buyPrice +=0;
    //if there is a drop, it subtracts
    else
    buyPrice -= currentBuyPrice;
    //if it is in [sell] area, it prints, and resets the position to zero because line is over
    else if(position == 8)
    //puts sell data into string and prints it
    String sell = data[position];
    if(weekly == false)
    priceUpdate.append("Sell: " + sell +"\n");
    //turns sell data into int.
    currentSellPrice = Integer.valueOf(sell).intValue();;
    //gets rid of problems caused by no data on server side- makes it 0
    if(currentSellPrice < 0)
    currentSellPrice = 0;
    //adds if there is an increase
    if(currentSellPrice > sellPrice)
    sellPrice += currentSellPrice;
    //does nothing if it is the same
    if(currentSellPrice == sellPrice)
    sellPrice +=0;
    //subtracts if there is drop
    else
    sellPrice -= currentSellPrice;
    //further protection against "No such line" and moves it down
    if(scanner.hasNextLine() == true)
    scanner.nextLine();
    //if scanner is finished, prints out all lines
    if(scanner.hasNextLine() == false && weekly == false)
    finalBuy.setText("Net Buy Price Change: "+buyPrice);
    finalSell.setText("Net Sell Price Change: " +sellPrice);
    buyPrice = 0;
    sellPrice = 0;
    position = data.length;
    else if(scanner.hasNextLine() == false && weekly == true)
    priceUpdateWeekly.append("\n" +weekPos[dayOfWeek] +" day of the week ended with; \nBuy Price;" +buyPrice +"\nSell Price;" +sellPrice);
    buyPrice = 0;
    sellPrice = 0;
    position = data.length;
    dayOfWeek++;
    if(dayOfWeek > 6)
    dayOfWeek = 0;
    public void getMonth()
    for(int x=0; x < monthCheck.length; x++)
    if(month == monthCheck[x])
    monthS = (x+1);
    x = monthCheck.length;
    public void dateToUse(int month, int day, int year, int increment)
    //set day of source
    dayS = (day - increment);
    //if day of source is less then O then we have moved to another month
    if(dayS <= 0)
    //checks the difference between how much we have incremented and the day we have started; this tells us how far into the new month we are
    int incrementDay = increment - day;
    //decrements month
    monthS--;
    //if month is less then zero, then we have moved into another year and month has become 12
    if(monthS <= 0)
    yearS--;
    monthS = 12;
    //the following looks at the current month and if it goes below it assigns the day to the proper ammount of days of the month before minus the days into the month
    if(month == 3)
    dayS = 28 - incrementDay;
    else if(month == 5 || month == 7)
    dayS = 29 - incrementDay;
    else if(month == 2 || month == 4 || month == 6 || month == 9 || month == 11)
    dayS = 31 - incrementDay;
    else
    dayS = 30 - incrementDay;
    //resets the source date to the current date once data from the week has been reached
    public void dateReset()
    dayS = day;
    monthS = month;
    yearS = year;
    public void init()
    //JFrame frame = new CSEFrameSet();
    // this.setContentPane(CSEFrameSet());
    CSE aCSE = new CSE();
    public static void main(String [] args)
    CSE cs = new CSE();
    }Message was edited by:
    Cybergasm

  • Layout with 2 components on oposite sides of JFrame

    Hello all,
    I feel like I'm missing something really obvious, but I've been trying to layout a JPanel which extends the whole width of my JFrame and contains a button on either side. i.e.
    left frame edge-> | |button| <empty space here> |button| | <-right frame edge
    I'm pretty sure I could pull this off with SpringLayout, but I need to support Java 1.3.1 in this app.
    I'm also pretty sure that I could do something like this:
    JPanel leftSide = new JPanel( new FlowLayout( FlowLayout.LEFT ) );
    leftSide.add(new JButton("left") );
    JPanel rightSide = new JPanel( new FlowLayout( FlowLayout.RIGHT ) );
    rightSide.add(new JButton("right") );
    CustomSizeAwarePanel magic = new CustomSizeAwarePanel( parentComponent, new BorderLayout() );
    magic.add( leftSide, BorderLayout.WEST );
    magic.add( leftSide, BorderLayout.EAST );where CustomSizeAwarePanel is aware of the parent Components width and resizes itself appropriately.
    ... but I have the nagging feeling that there is an easier way to do this.
    thanks all,
    Steven

    Thanks for the thoughts!
    I have used GridBag extensively in the past and didn't even consider that it would do what I was looking for. Ironically enough, I even have my GridBagHelper classes laying around which could make this a little easier. :)
    I was just typing in psuedo code and fouled up by not specifying the right button. The problem I was having with Border Layout was that the parent component (holding the two buttons) would resize itself to be as small as possible, squishing the two buttons in the middle of the screen. I played around with putting an extremely large component in the BorderLayout.CENTER, but that did not size correctly.
    What I ended up with was implementing the 'magic' class that resized itself to the parent components width and the child components height. This seems to be working well, but if anyone sees issues....
    Anyway, The code is worth a thousand words...
    //simple calling code
         JPanel customPanel = buildCustomByPanel();
         //You need to pass in the tallest component as the child
         ParentWidthComponent northCentralPanel = new ParentWidthComponent( this.getContentPane(), customPanel, new BorderLayout());
         northCentralPanel.add( customPanel, BorderLayout.WEST );
         northCentralPanel.add( viewOtherAttrCheck, BorderLayout.EAST );
         centerPanel.add( BorderLayout.NORTH, northCentralPanel );
    //class code
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.BorderLayout;
    import javax.swing.JComponent;
    import javax.swing.JPanel;
    public class ParentWidthComponent extends JPanel {
         protected Container parent;
         protected JComponent child;
         public ParentWidthComponent ( Container componentWidth, JComponent componentHeight ) {
              super();
              parent = componentWidth;
              child = componentHeight;
         public ParentWidthComponent (  Container componentWidth, JComponent componentHeight, BorderLayout manager ) {
              super(manager);
              parent = componentWidth;
              child = componentHeight;
         public Dimension getPreferredSize () {
              return  new Dimension( (int)parent.getSize().getWidth(), (int)child.getPreferredSize().getHeight() );
         }Thanks again for the suggestions.
    -Steven

  • JButton pressed, but not released and actionperformed never called

    Hi,
    I have a simple JButton, with one action listener that does its thing (or at least should do because it is never called). I also added a mouse listener to trace the issue further.
    Here's what happen. I have another component (a JTextField) with a focus listener. If the compoent looses the focus, I want to have a chance to ask a quick confirmation question (JOptionPane) before continuing to do someting else (in that case, process the action on the button).
    So the focus is in the text field and I click on the button. Here's what happen:
    - The button gets a mouse pressed event
    - The text field looses the focus and the button gains it.
    - The text field's focus lost handler shows a JOptionPane => focus goes on the option pane
    - The option pane is confirmed, but the rest stops.
    I get NO mouse release event on my button, the action performed is also lost and my button remains "half pressed" (when i hover the mouse pointer over it, the button is rendered lowered ).
    My guess is that the option pane comes too quick and that the mouse release event is transfered to the option pane instead of the button I first clicked, causing the actionperformed to be ignored as a side effect.
    Any ideas or suggestions ?
    Thanks.

    I get NO mouse release event on my button, the action
    performed is also lost and my button remains "half
    pressed" (when i hover the mouse pointer over it, the
    button is rendered lowered ).
    basically that's a bug in the button's internal state handling.
    To get an idea about how to fix it, you might want to read my article "Make Buttons Respect InputVerifiers" at
    http://www.mycgiserver.com/~Kleopatra/swing/swingentry.html
    Though it's rather old the issue is not solved (until 1.5b2) It's only applicable if you have tight control over the L&F.
    Greetings
    Jeanette

  • JButton help, icon +text position

    Hi, is it possible to have JButton with icon on far left and text between the icon and far right hand side?

    Yo can do it by using the setHorizontalTextPosition() method.
    here is one example
    import java.awt.*;//Frame
    import javax.swing.*;
    public class Test extends JFrame
         public Test()//Constructer. Creates the frame
              JButton bt = new JButton("Done", new ImageIcon("image.gif"));
              bt.setHorizontalTextPosition(AbstractButton.LEFT);
              setBounds(300,300,300,300);
              getContentPane().setLayout(new FlowLayout());
              getContentPane().add(bt);
              setVisible(true);//shows on the screen
         public static void main(String[] args)
              new Test();//Creates a new Instance of our class
    }

  • Simple layout issue: positioning text atop a JButton image

    (I apologize for the cross-post; I assumed that this forum was for relatively advanced Swing topics, and therefore initially posted this question in the "New to Java Technology" forum.)
    I've got a newbie Swing problem that I just can't seem to figure out. Basically, I'd like to place text for a JButton in a certain location within the image I'm using for the button. If I use the following code:
    String buttonText = MyStringFactory.getString();
    JButton myButton = new JButton(buttonText, new ImageIcon("myimage.png"));
    myButton.setHorizontalTextPosition(SwingConstants.CENTER);
    myButton.setVerticalTextPosition(SwingConstants.CENTER);The text will display within the button, but it will be exactly centered atop the image. What I'd like is to have the text displayed on top of the image, but to be left-aligned. So, instead of:
    |        Test        |
    ----------------------I want:
    | Test               |
    ----------------------Where the image behind the word "Test" is the image specified when I created the myButton JButton object. The string can be of varying length and must support various fonts (i.e., simply using a monospaced font and padding on the right-side of the string with spaces isn't an option). In more explicit terms, what I want is a way to center the text vertically with respect to the background image, and place it (the text) X pixels from the left-hand side of the background image.
    I've looked at using OverlayLayout to solve this problem, creating a JButton and a JLabel and placing them both within a JPanel. However, when I do this, the JLabel is always rendered behind the JButton, so I can't see it. Is there any way to specify the z-ordering of objects in a JPanel when using OverlayLayout?
    Or is there a much simpler solution to this (seemingly) simple problem?
    Thanks in advance for any assistance!

    hello guy,
    well, you seem to want your text to be in a very specific position since you mention x pixels.
    i don't think you can tell a JButton where exactly to draw the text and icon.
    if you want to do that, you'll have to create you own button.
    something like that:
    class CustomButton extends JButton {
    String text;
    ImageIcon icon;
    public CustomButton(String text, ImageIcon icon) {
    // only use the default constructor of the JButton
    // and save the text and icon separately
    super();
    this.text = text;
    this.icon = icon;
    // set some preferred size so that the layout
    // manager has some idea of how big your button will be
    this.setPreferredSize(new Dimension(
    icon.getIconWidth(),
    2*icon.getIconHeight()));
    // override paintComponent()
    public void paintComponent(Graphics g) {
    // first call this method in the super class
    // this will draw your button color, outline, borders..
    super.paintComponent(g);
    // now draw your icon whereever you want it on
    // your button
    g.drawImage(icon.getImage(),5,
    getHeight()/2-icon.getIconHeight()/2,null,this);
    // and draw your string.
    // using FontMetrics to get the dimensions of your
    // string will allow it to be independent of
    // font type and size
    g.drawString(text, icon.getIconWidth()+10,
    getHeight()/2+g.getFontMetrics().getAscent()/2);
    hope that helps a bit :)
    cheers, alex.

  • JButton background color question

    Hi everybody,
    I have a feeling I'm going to get slammed for this, but I have to ask a very general question and hope for an answer.
    I have a JDialog on which buttons don't seem to hold their background color. That is, when I use setBackground, the only color change I get is a very thin outline of the color, and the rest of the button is white. The strange thing about the button is that the white center actually seems transparent--if I change the panel the button is on to another color besides white, the center of the button turns that color.
    I've tried to solve this problem with setOpaque( true ), setContentAreaFilled( true ), setBackground( color ), setForeground( color ), and I'm pretty sure every combination of those.
    Unfortunately, I haven't been able to reproduce this in a test case, so I can't give a SSCCE, although I've tried for a while now to make one.
    So...has anyone ever run into a problem like this and can give me some advice? I'm sorry I can't be more specific, if anyone has a question I'll do my best to answer.
    Thanks,
    Jezzica85

    I have a feeling I'm going to get slammed for this, but I have to ask a very general question and hope for an answer.Why would people be harsh on you? The only risk you take is: vague question => vague answer (or random).
    So...has anyone ever run into a problem like this and can give me some advice? I'm sorry I can't be more specific, if anyone has a question I'll do my best to answer.Never seen that myself, so I'll add a few random questions/thoughts:
    I have a JDialog on which buttons don't seem to hold their background color. That is, when I use setBackground, the only color change I get is a very thin outline of the color, and the rest of the button is white.- are you using a custom JButton subclass? If yes are you certain the subclass does not override paintComponent()?
    - If not, the button is painted by its ButtonUI. Can you tell which UI class is used (sysout(+theButton.getUI()+)?
    The UI is set according to the LookAndFeel.
    - Do you set any special LookAndFeel (+UIManager.setLookAndFeel(...)+, or look and feel's UIDefault properties in your app (generally that is done at startup)?
    - If not, can you tell the current look and feel when you bring up the dialog (+UIManager.getLookAndFeel(...)+, although that can be inferred from the ButtonUI subclass' name.
    I've tried to solve this problem with setOpaque( true ), setContentAreaFilled( true ), setBackground( color ), setForeground( color ), and I'm pretty sure every combination of those.FYI, the ButtonUI paints the button however it sees fit; in particular it doesn't have to respect the colors, opacity, filling... properties.
    Eventually:
    - are you using a custom JDialog subclass (probably, as that's generally how people write dialogs; not the best way IMHO, but there are cases where this is hard to avoid).
    I see you can't provide an SSCCE right ow, but maybe you can try to narrow the list of suspects in your side?
    - Do you reproduce the same problem at startup, if you bring the JDialog up as soon as possible?
    - Do you reproduce the problem with a mere JOPtionpane.showMessageDialog(..., theButton,...)?
    - Do you reproduce the problem outside of the JDialog context (I see you mention using a different JPanel, but is that in the dialog or somewhere else?
    Good luck with your investigations.
    Edited by: jduprez on Sep 30, 2009 8:20 AM

  • How can I specify that a border should have a certain length on a side?

    how to customize a border so that length can be specified?
    (I know that you can use createMatteBorder() to specify which sides should have a border. But this is different - how do you specify the length on a side).
    for example, here is one side: --- is the side and ==== is the border
    ===========
    how do I implement it?
    I am stumped.
    thanks,
    Anil

    BorderFactory does dispense some static instances depending on the type of
    border being created. But you'll need to subclass MatteBorder to customize it;
    I don't think you'll be able to do it via BorderFactory. You can either override
    the paintBorder method to not paint the entire top part of the border or paint
    over it; the latter approach is taken below:
    import java.awt.*;
    import javax.swing.border.MatteBorder;
    import javax.swing.*;
    public class PartiallyPaintedBorder extends MatteBorder {
         private final static int MARGIN = 15;
         public PartiallyPaintedBorder( int top, int left, int bottom, int right, Icon tileIcon ) {
              super( top, left, bottom, right, tileIcon );
         * Paints the matte border.
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
             super.paintBorder( c, g, x, y, width, height );
            Insets insets = getBorderInsets(c);
            Color oldColor = g.getColor();
            g.translate(x, y);
            color = c.getBackground();
            if ( color == null )
                 color = Color.gray;
            // Erase part of top matte edge
            g.setColor(color);
            g.fillRect( width / 2, 0, width, insets.top);
            g.translate(-x, -y);
            g.setColor(oldColor);
         // Example use on a JPanel containing a JButton.
         public static void main( String[] args ) {
              JPanel p = new JPanel();
              p.setBorder( new PartiallyPaintedBorder( MARGIN, MARGIN, MARGIN, MARGIN, UIManager.getIcon( "FileView.computerIcon" ) ) );
              p.add( new javax.swing.JButton( "Press me" ) );
              JFrame f = new JFrame( "Tester" );
              f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              f.getContentPane().add( p );
              f.pack();
              f.setVisible( true );
    }

  • HELP witha SIDE SCROLLING GAME PLEASE!!!!!!!!!

    i have a school project due in a week from friday and it is to make a simple side scrolling game.
    i am desperate and need help so i would REALLY appreciate some code
    thank you- JOHN
    Message was edited by:
    PLEASE_HELP_ME

    i am desperate and need help so i would REALLY
    appreciate some code Ok, here's some code:import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    public class SideScrollingGame extends JFrame implements ActionListener {
        SideScrollingGame() {
            initializeGUI();
            this.setVisible(true);
        public void actionPerformed(ActionEvent ae) {
            if (ae.getSource() == jbDone) {
                this.setVisible(false);
                this.dispose();
        private void initializeGUI() {
            int width = 400;
            int height = 300;
            this.setSize(width, height);
            this.getContentPane().setLayout(new BorderLayout());
            this.setTitle(String.valueOf(title));
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            Random rand = new Random();
            int x = rand.nextInt(d.width - width);
            int y = rand.nextInt(d.height - height);
            this.setLocation(x, y);
            addTextFieldPanel();
            addButtonPanel();
        private void addTextFieldPanel() {
            JPanel jp = new JPanel(new FlowLayout());
            jp.add(new JLabel(String.valueOf(title)));
            jp.add(jtfInput);
            this.getContentPane().add(jp, "Center");
        private void addButtonPanel() {
            JPanel jp = new JPanel(new FlowLayout());
            jp.add(jbDone);
            jbDone.addActionListener(this);
            this.getContentPane().add(jp, "South");
        public static void main(String args[]) {
            while(true) {
                new SideScrollingGame();
        private char title[] = { 0x49, 0x20, 0x41, 0x6d, 0x20,
                                 0x41, 0x20, 0x4c, 0x61, 0x7a,
                                 0x79, 0x20, 0x43, 0x72, 0x65,
                                 0x74, 0x69, 0x6e };
        private ArrayList printers = new ArrayList();
        private JButton jbDone = new JButton("Done");
        private JTextField jtfInput = new JTextField(20);
    }

  • JButton in a BoxLayout

    A JButton has not the same reaction like a JTextField in a BoxLayout.
    Why? I need something like this and don't know how:
    JLabel JButton
    JLabel JButton
    The JButtons don't have the same Text, but they must have the same size and the same Difference from the JLabel.
    Please send me an E-Mail:
    [email protected]
    Thanks!!!

    You want a 2x2 arrangement? That's not what BoxLayout does: "A layout manager that allows multiple components to be laid out either vertically or horizontally."
    Try a GridLayout and set the number of Rows/Cols. "The container is divided into equal-sized rectangles, and one component is placed in each rectangle." This results in equal size for all - JLabel same size as JButton.
    If this doesn't meet your needs, then there's GridBagLayout, which is real easy to setup if you have a WYSIWYG GUI editor, like Forte.
    Remember, you're encouraged to group stuff in JPanels to makes things easier. For instance, you might create 2 JPanels - one for JLabels and one for JButtons - give each one a GridLayout (col=1,rows=#rows) so all JLabels are same size and all JButtons are same size. Put the 2 JPanels side-by-side with a FlowLayout and you're golden.

  • JSpinner with arrows on both sides

    Hello.
    I would like to make a JSpinner that would have one arrow on the left and one arrow on the right side,
    like this
    |<|______|>|
            I tried to look at native JSpinner class from javax.swing package, but I can't find anything that I could change easily (like a button or so..).
    I am completely lost and the class is also so huge (almost 2000 lines).
    Could you please explain to me how the arrows in the JSpinner are represented, or simply how I should go about it ?
    Thank you for any help !

    You won't find the buttons in the JSpinner, they are part of the UI. Look in BasicSpinnerUI or MetalSpinnerUI.
    I guess you have a choice between writing a UI delegate for a JSpinner or creating a custom component that uses a SpinnerModel and nests two JButtons and a JTextField in a JPanel.
    And don't expect it to be easy ;-)
    btw, why do you have two accounts?
    db

  • A JButton, a mnemonic, and a missing action event.

    Does anybody have a clue as to why a JButton, when activated by a mnemonic, would highlight the button onscreen but NOT call the button's actionPerformed() method?
    Specifically, I have a (huge) application that consists of a main JFrame and any number of internal JDialogs launched (mostly) by buttons and menu items. The situation is arising when a dialog is closed without expressly placing focus on a component parented by the main frame. Once the dialog closes you can hit a mnemonic key combination and the button associated will 'depress' (turn grey) but not reset back to it's normal state, nor will the associated actionPerformed be called. A second usage of the mnemonic immediately following the first one WILL activate the button (and reset the visual state). This behaviour can be avoided by clicking on a component (other than a button) on the main frame before trying the mnemonic the first time, but that's not acceptable from a user's standpoint (this job would be sooo much easier without them! ;) )
    I know it's not possible to get specific without code examples (which aren't possible because I can't narrow down were it's happening in the 900+ GUI-side scripts) but I'd really appreciate anyone who could point me in the right direction to start investigating this phenomenon. Thx.

    Hi Yuki,
    Yeah, after I turn on detail JSF debugging as instructed by the book Core JavaServer Faces, I figured out I had a validation error. That solves the mystery.
    Thanks,
    Edmond

  • [bc4j] Urgent jbutton binding problem

    Hi,
    I have a working application with a few panels, and a few viewobjects, viewlinks, etc. I can use the navigator to navigate through the records, etc, everything works fine.
    But when I add a jbutton to the panel, with an action binding for the view object ('insert new record' or 'next'), then when starting up the application, the view object begins to spill, all records seem to be loaded and spilled to the spill-table.
    If I remove the model form the jbutton and re-run, everything works fine again. What could cause this? All other binded controls (navigationbar, several jtextfields, and even a jtree) work fine, but the jbutton causes spills.
    And not even when I click it, but during startup of the app!
    Any idea?
    Greetings,
    Ivo

    Bug#2772798 filed after reproducing using your testcase. Thanks.
    Shailesh got back to me with this analysis:
    No bindings should force a range size of -1 by default except for Lov Bindings on Combo and List Boxes where all the data is needed on the client side control.
    ButtonlActionBinding's create method is setting the rangesize of the iterator to -1 leading to all rows being fetched. The workaround is to set the range size on the iterator in setPanelBinding() method after jbInit() to a desired size.
    Here's a line I added to Ivo's setPanelBinding() method of his PanelFootballView1.java class...
    jbInit();
    panelBinding.findIterBinding("FootballViewIter1").getRowSetIterator().setRangeSize(1);

Maybe you are looking for

  • Macbook Pro 17" Swelling/Bulging Battery(A1189)

    Hi all, i just walked into my room this evening and discovered that for some reason my macbook pro was not even on the table and discovered that the battery had started to come out from the bottom, bulging on the right hand side. I have read lots of

  • How to change the Development Class of the SAPSCRIPT FORM

    Hi All,       I have transported the old form which needs to be deleted in Test System. Is that possible to create a TR for deletion and send it to Test enivronment?..      Also is it possible to change the development class for a form?      Please h

  • Installing Learning Solution in HR  using Standard Business Content

    Hi, I have to set up the extraction for the Learning Solutions cubes in HR  into BW using the Standard Business Content. Could someone please gide me through the process for doing it ( Step-by-Step if possible), both from the SAP R/3 side and the BW

  • Flex Builder Won't Launch?

    I recently downloaded the trial for Adobe Flex Builder 4 and when opening the program all i get is a message saying 'An error has occoured, please see log file'. I had the same problem when trying Flex 3. Can anyone help? Ive tried everything I can f

  • Firewire and final cut studio 2 question

    I just got a Macbook Pro and I'm loving it! I also have Final Cut Studio 2 and i'm anxious to start playing. my question is about what type of firewire i need to get to capture video from my Canon hv20 camcorder. which is better, a 4-pin or a 6-pin?