Search Results

Search found 491 results on 20 pages for 'jframe'.

Page 16/20 | < Previous Page | 12 13 14 15 16 17 18 19 20  | Next Page >

  • Getting JRuby to work in RubyMine

    - by John Baker
    I setup the proper SDK because all my ruby code will compile but RubyMine complains that it can't find the any of my java classes? Is this a flaw or is there a way to get it to recognizewhere the classes are? Here is my code, I have underlined all the things its complaining about require 'java' include_class 'java.awt.event.ActionListener' include_class 'javax.swing.JButton' include_class 'javax.swing.JFrame' class ClickAction include ActionListener def action_performed(event) puts "Button got clicked." end end Is there a way around this because I'd love to buy RubyMine if it's able to inform me of what Java classes and methods I can pick from. Thanks

    Read the article

  • JMenuBar dropping down to a "custom" JPanel and "erased"

    - by Jani
    The JMenuItems of JMenuBar drops down to a JPanel added to the JFrame, but the JPanel erases the JMenuItems. Do I supposed to pause the re-drawing of the JPanel? I'm using getGraphics() on the JPanel for drawing an image, this method is called from a thread with (for example) 200 ms delay. edit: It's a (very simple) game inside the JPanel. (I've added a field "paused" to the JPanel and i've edited the paint method so it repaints the JPanel only if paused is false, however I don't know if this "solution" is good. (It's set to true when the user clicks on a menu and set to false when selects or cancels it.)

    Read the article

  • Using an array as parameter to a class.

    - by Gabriel A. Zorrilla
    I have created an array Man: public main blah blah{ man = man[10]; } Man has fields such as Man.name; Man.age; ... In Man class, there is a OnClick method that opens a new window showing its name and age. public Man(){ Onclick(){ InfoWindow showinfo = new InfoWindow(this.getid()) // If this is Man[2] the id would be 2. } And in InfoWindow class: public class InfoWindow extends JFrame{ public InfoWindow(Man selectedMan){ setSize(300, 200); JLabel info = new JLabel(selectedMan.getname()); add(info); info.setVisible(true); } } Basically, that's wanna acomplish (show in pseudocode), pass a Man[i] into a class that when a window is created, shows the info related to that man. This is how i'm actualy trying to implement it but it's not working, i'm pretty sure there is a misconception from me in some part. Any help?

    Read the article

  • Problem with FlowLayout

    - by atch
    public class MyFrame extends JFrame { public MyFrame(String title) { setSize(200, 200); setTitle(Integer.toString(super.getSize().width)); setLayout(new FlowLayout()); for (int i = 0; i < 5; ++i) { JButton b = new JButton(); b.setSize(90,50); b.setText(Integer.toString(b.getSize().width)); this.add(b);![alt text][1] } this.setVisible(true); } } why if having button widht 90 I'm getting window where three buttons are in one row instead of two?

    Read the article

  • Java - AWT / Swing - handling the Event Descriptor Thread

    - by waitinforatrain
    Hi, I have a question about the 'Event Descriptor Thread'. I have a Main class that is also a JFrame. It initialises the rest of the components in the code, some of them do not involve Swing and some of them do. Is it enough to simply initialise the Main class using the EDT like this?... public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { new Main(); } }); } This way everything would run on the Event Dispatcher thread.

    Read the article

  • Adding a JPanel to another JPanel having TableLayout

    - by user253530
    I am trying to develop a map editor in java. My map window receives as a constructor a Map object. From that map object i am able to retrieve the Grid and every item in the grid along with other getters and setters. The problem is that even though the Mapping extends JComponent, when I place it in a panel it is not painted. I have overridden the paint method to satisfy my needs. Here is the code, maybe you could help me. public class MapTest extends JFrame implements ActionListener { private JPanel mainPanel; private JPanel mapPanel; private JPanel minimapPanel; private JPanel relationPanel; private TableLayout tableLayout; private JPanel tile; MapTest(Map map) { mainPanel = (JPanel) getContentPane(); mapPanel = new JPanel(); populateMapPanel(map); mainPanel.add(mapPanel); this.setPreferredSize(new Dimension(800, 600)); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } private double[][] generateTableLayoutSize(int x, int y, int size) { double panelSize[][] = new double[x][y]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { panelSize[i][j] = size; } } return panelSize; } private void populateMapPanel(Map map) { double[][] layoutSize = generateTableLayoutSize(map.getMapGrid().getRows(), map.getMapGrid().getColumns(), 50); tableLayout = new TableLayout(layoutSize); for(int i = 0; i < map.getMapGrid().getRows(); i++) { for(int j = 0; j < map.getMapGrid().getColumns(); j++) { tile = new JPanel(); tile.setName(String.valueOf(((Mapping)map.getMapGrid().getItem(i, j)).getCharacter())); tile.add(map.getMapItem(i, j)); String constraint = i + "," + j; mapPanel.add(tile, constraint); } } mapPanel.validate(); mapPanel.repaint(); } public void actionPerformed(ActionEvent e) { throw new UnsupportedOperationException("Not supported yet."); } } My Mapping Class public class Mapping extends JComponent implements Serializable{ private BufferedImage image; private Character character; //default public Mapping() { super(); this.image = null; this.character = '\u0000'; } //Mapping from image and char public Mapping(BufferedImage image, char character) { super(); this.image = image; this.character = character; } //Mapping from file and char public Mapping(File file, char character) { try { this.image = ImageIO.read(file); this.character = character; } catch (IOException ex) { System.out.println(ex); } } public char getCharacter() { return character; } public void setCharacter(char character) { this.character = character; } public BufferedImage getImage() { return image; } public void setImage(BufferedImage image) { this.image = image; repaint(); } @Override /*Two mappings are consider the same if -they have the same image OR -they have the same character OR -both of the above*/ public boolean equals(Object mapping) { if (this == mapping) { return true; } if (mapping instanceof Mapping) { return true; } //WARNING! equals might not work for images return (this.getImage()).equals(((Mapping) mapping).getImage()) || (this.getCharacter()) == (((Mapping) mapping).getCharacter()); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); //g.drawImage(image, 0, 0, null); g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), null); } // @Override // public Dimension getPreferredSize() { // if (image == null) { // return new Dimension(10, 10); //instead of 100,100 set any prefered dimentions // } else { // return new Dimension(100, 100);//(image.getWidth(null), image.getHeight(null)); // } // } private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { character = (Character) in.readObject(); image = ImageIO.read(ImageIO.createImageInputStream(in)); } private void writeObject(java.io.ObjectOutputStream out) throws IOException { out.writeObject(character); ImageWriter writer = (ImageWriter) ImageIO.getImageWritersBySuffix("jpg").next(); writer.setOutput(ImageIO.createImageOutputStream(out)); ImageWriteParam param = writer.getDefaultWriteParam(); param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); param.setCompressionQuality(0.85f); writer.write(null, new IIOImage(image, null, null), param); } }

    Read the article

  • Adding JPanel onto another JPanel after button click

    - by user1400650
    I'm using Netbeans IDE to make a gui application. I have a JFrame with a JPanel inside it. After a button click I want to display a different JPanel inside the first. The other JPanel is in a different file. How would I go about doing this? If this is not practical I don't mind replacing the first JPanel with the second one. I've tried the following but it doesn't seem to work. I'm new to Java and Gui programming so I would appreciate any help I can get. private void jButtonActionPerformed(java.awt.event.ActionEvent evt) { JPanel2 jPanel2 = new JPanel2(); JPanel1.add(jPanel2); }

    Read the article

  • Stop a stopwatch

    - by James Morgan
    I have the following code in a JPanel class which is added to a another class (JFrame). What I'm trying to implement is some sort of a stopwatch program. startBtn.addActionListener(new startListener()); class startListener implements ActionListener { public void actionPerformed(ActionEvent e) { Timer time = new Timer(); time.scheduleAtFixedRate(new Stopwatch(), 1000, 1000); } } This is another class which basically the task. public class Stopwatch extends TimerTask { private final double start = System.currentTimeMillis(); public void run() { double curr = System.currentTimeMillis(); System.out.println((curr - start) / 1000); } } The timer works fine and this is definitely far from complete but I'm not sure how to code the stop button which should stop the timer. Any advice on this? BTW I'm using java.util.timer

    Read the article

  • o display an image

    - by Vimal Basdeo
    I want to display an image from the web to a panel in another Jframe at the click of a button but whenever I click the button first the image loads and during this time the current form potentially freezes and once the image has loaded the form is displayed with the image.. How can I avoid the situation where my form freezes since it is very irritating My codes :: My current class private void btn_TrackbusActionPerformed(java.awt.event.ActionEvent evt) { try { sendMessage("Query,map,$,start,211,Arsenal,!"); System.out.println(receiveMessage()); } catch (UnknownHostException ex) { Logger.getLogger(client_Trackbus.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(client_Trackbus.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(client_Trackbus.class.getName()).log(Level.SEVERE, null, ex); } client_trackedbus nextform=new client_trackedbus(planform,connection,packet_receive,packet_send); this.setVisible(false); this.dispose(); nextform.setVisible(true); // TODO add your handling code here: } My next class that displays the image public class client_trackedbus extends javax.swing.JFrame { client_planform planform=null; DatagramSocket connection=null; DatagramPacket packet_receive=null; DatagramPacket packet_send=null; JLabel label=null; /** Creates new form client_trackedbus */ public client_trackedbus(client_planform planform,DatagramSocket connection,DatagramPacket packet_receive,DatagramPacket packet_send) { initComponents(); this.planform=planform; this.connection=connection; this.packet_receive=packet_receive; this.packet_send=packet_send; try { displayMap("http://www.huddletogether.com/projects/lightbox2/images/image-2.jpg", jPanel1, new JLabel()); } catch (MalformedURLException ex) { Logger.getLogger(client_trackedbus.class.getName()).log(Level.SEVERE, null, ex); } } private void displayMap(String url,JPanel panel,JLabel label) throws MalformedURLException{ URL imageurl=new URL(url); Image image=(Toolkit.getDefaultToolkit().createImage(imageurl)); ImageIcon icon = new ImageIcon(image); label.setIcon(icon); panel.add(label); // System.out.println(panel.getSize().width); this.getContentPane().add(panel); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); btn_Exit = new javax.swing.JButton(); btn_Plan = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Public Transport Journey Planner"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 368, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 172, Short.MAX_VALUE) ); jLabel1.setFont(new java.awt.Font("Arial", 1, 18)); jLabel1.setText("Your tracked bus"); btn_Exit.setText("Exit"); btn_Exit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btn_ExitActionPerformed(evt); } }); btn_Plan.setText("Plan journey"); btn_Plan.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btn_PlanActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(104, 104, 104) .addComponent(jLabel1)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(65, 65, 65) .addComponent(btn_Plan) .addGap(65, 65, 65) .addComponent(btn_Exit, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(20, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(35, 35, 35) .addComponent(jLabel1) .addGap(18, 18, 18) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btn_Exit) .addComponent(btn_Plan)) .addContainerGap(12, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void btn_ExitActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Exitform(); } private void btn_PlanActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: this.setVisible(false); this.dispose(); this.planform.setVisible(true); } private void Exitform(){ this.setVisible(false); this.dispose(); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { // new client_trackedbus().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btn_Exit; private javax.swing.JButton btn_Plan; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; // End of variables declaration }

    Read the article

  • Netbeans GUI editor generating its own incomprehensible code.

    - by WarDoGG
    When creating a new project in netbeans, if i select JAVA Desktop application, it creates some code which I DO NOT RECOGNISE AT ALL as what i had learnt in swing. It imports packages such as : org.jdesktop.application.SingleFrameApplication; also, the declaration for main() looks like this : public static void main(String[] args) { launch(DesktopApplication2.class, args); } This really does not make any sense to my knowledge of JFrame, JPanel etc.. If i try to code a netbeans application from scratch, i can write my own swing app BUT I CANNOT FIND THE GUI EDITOR. How do i bring the GUI editor when creating java application from scratch ? Can anyone explain to me this org.jdesktop.application.SingleFrameApplication and other classes ? Please help. This is really frustrating.

    Read the article

  • Java MVC - How to divide a done text game into MVC?

    - by Zopyrus
    Been sitting here for hours now trying to figure this out, so a bit sympathy for this large question. :) The Goal: I simply want to divide my done code into MVC (Model View Controller) parts. I have the game logics done and text based - the code works fine. The Problem: Well, I want to implement this code into MVC, but where do explain for the MODEL that it should use text-based? Because the VIEW is only for the layout (graphically) correct? I am having a REALLY hard time figuring out where to begin at all. Any pointers would be so nice! Here is my game logics code: import mind.*; import javax.swing.*; import java.util.*; import java.lang.*; import java.awt.*; public class Drive { String[] mellan; boolean gameEnd, checkempty, checkempty2, enemy, enemy2; String gr,rd,tom; int digits; public Drive() { // Gamepieces in textform gr="G"; rd="R"; tom=" "; mellan = new String[7]; String[] begin = {gr,gr,gr,tom,rd,rd,rd}; String[] end = {rd,rd,rd,tom,gr,gr,gr}; //input Scanner in = new Scanner(System.in); mellan=begin; gameEnd=false; while (gameEnd == false) { for(int i=0; i<mellan.length; i++) { System.out.print(mellan[i]); } System.out.print(" Choose 0-6: "); digits = in.nextInt(); move(); checkWin(); } } void move() { //BOOLEAN for gameruls!!! checkempty = digits<6 && mellan[digits+1]==tom; checkempty2 = digits>0 && mellan[digits-1]==tom; enemy = (mellan[digits]==gr && mellan[digits+1]==rd && mellan[digits+2]==tom); enemy2 = (mellan[digits]==rd && mellan[digits-1]==gr && mellan[digits-2]==tom); if(checkempty) { mellan[digits+1]=mellan[digits]; mellan[digits]=tom; } else if (checkempty2) { mellan[digits-1]=mellan[digits]; mellan[digits]=tom; } else if (enemy) { mellan[digits+2]=mellan[digits]; mellan[digits]=tom; } else if (enemy2) { mellan[digits-2]=mellan[digits]; mellan[digits]=tom; } } void checkWin() { String[] end = {rd,rd,rd,tom,gr,gr,gr}; for (int i=0; i<mellan.length; i++){ } if (Arrays.equals(mellan,end)) { for (int j=0; j<mellan.length; j++) { System.out.print(mellan[j]); } displayWin(); } } void displayWin() { gameEnd = true; System.out.println("\nNicely Done!"); return; } // Kör Drive! public static void main(String args[]) { new Drive(); } } Here is how I defined my DriveView thus far: (just trying to make one button to work) import mind.*; import javax.swing.*; import java.util.*; import java.lang.*; import java.awt.*; import java.awt.event.*; public class DriveView extends JFrame { JButton ruta1 = new JButton("Green"); JButton ruta2 = new JButton("Green"); JButton rutatom = new JButton(""); JButton ruta6 = new JButton("Red"); private DriveModel m_model; public DriveView(DriveModel model) { m_model = model; //Layout for View JPanel myPanel = new JPanel(); myPanel.setLayout(new FlowLayout()); myPanel.add(ruta1); myPanel.add(ruta2); myPanel.add(rutatom); myPanel.add(ruta6); this.setContentPane(myPanel); this.pack(); this.setTitle("Drive"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } void addMouseListener(ActionListener mol) { ruta2.addActionListener(mol); } } And DriveController which gives me error at compile import mind.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.lang.*; public class DriveController { private DriveModel m_model; private DriveView m_view; public DriveController(DriveModel model, DriveView view) { m_model = model; m_view = view; view.addMouseListener(new MouseListener()); } class MouseListener implements ActionListener { public void actionPerformed(ActionEvent e) { String mening; mening = e.getActionCommand(); if (mening.equals("Green")) { setForeground(Color.red); } } } }

    Read the article

  • Icon in titledBorder title

    - by Venno
    Hi is it possible to place an icon in the title of a titledBorder for example the following code: import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.border.TitledBorder; public class TitledExample extends JPanel { public TitledExample() { super(true); this.setLayout(new GridLayout(1, 1, 5, 5)); JLabel label = new JLabel("Titled Border"); label.setHorizontalAlignment(JLabel.CENTER); TitledBorder titled = new TitledBorder("Image here ?? Title"); label.setBorder(titled); add(label); } Thanks , Cheers

    Read the article

  • JComponent undock effect

    - by Christo Du Preez
    I'm trying to accomplish an undock effect for a custom Swing JComponent. By default the component is used inside a form along with other components. I want to be able to maximize this component to use the whole screen and then be able to dock it again. So far I've tested public void showDialog() { JFrame mainFrame = App.getApplication().getMainFrame(); JDialog dialog = new JDialog(mainFrame); dialog.setModal(true); dialog.setSize(800, 600); //Set to 80x660 for now dialog.add(this); //This is my JComponent dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); } This gives me desired effect but when closing the dialog my component doesn't receive events no more. How can I prevent this? Or is there perhaps a better way to accomplish this?

    Read the article

  • Swing Panel Question

    - by dalton conley
    Ok, so I've been pulling my hair out over this all day. I cannot get my panels to resize. I add a panel to anything.. a frame, a content pane, and It wont .. "force" setBounds for some strange reason. Container pane = window.getContentPane(); JPanel calendarPanel = new JPanel(); pane.add(calendarPanel); calendarPanel.setBounds(0,0, 320, 335); note that window is of JFrame. Any suggestions to sizing a panel would be appreciated!

    Read the article

  • Java: Get Mainform object from JInternalFrame

    - by rodion
    Can I do this without reference to the object in the constructor? In other words, any class inherited from FrmTaoChild when creating must to add the button on the toolbar of the main window public class FrmTaoMain extends JFrame { JToolBar tbTask = new JToolBar(); public FrmTaoMain(String Caption) { super(Caption); ... FrmTaoChild FrmChild = new FrmTaoChild(tbTask,"test"); } } public class FrmTaoChild extends JInternalFrame { public FrmTaoChild(JToolBar tbTask, String Caption) { super (Caption); JButton btnTask = new JButton(Caption); tbTask.add(btnTask); } }

    Read the article

  • How to check all check boxes at a click of a button

    - by LivingThing
    I am new to Swing, UI and MVC I have created a code based on MVC. Now my problem is that that in the controller part i have an actioneventlistener which listens to different button clicks. Out of all those buttons i have "select all" and "de-select all". In my view i have a table, one of the column of that table contains "check boxes". Now, when i click the "select-all" button i want to check all the check boxes and with "de-select all" i want to uncheck all of them. Below is my code which is not working. Please tell me what am i doing wrong here. Also, if someone knows a more elagent way please share. Thanks In my view public class CustomerSelectorDialogUI extends JFrame{ public CustomerSelectorDialogUI(TestApplicationUI ownerView, DummyCustomerStore dCStore, boolean modality) { //super(ownerView, modality); setTitle("[=] Customer Selection Dialog [=]"); //setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); custSelectPanel = new JPanel(); buttonPanel = new JPanel(); selectAllButton = new JButton(" Select All "); clearAllButton = new JButton(" Clear All "); applyButton = new JButton(" Apply "); cancelButton = new JButton(" Cancel "); PopulateAndShow(dCStore, Boolean.FALSE); } public void PopulateAndShow(DummyCustomerStore dCStore, Boolean select) { List data = new ArrayList(); for (Customer customer : dCStore.getAllCustomers()) { Object record[] = new Object[COLUMN_COUNT]; record[0] = (select == false) ? Boolean.FALSE : Boolean.TRUE; record[1] = Integer.toString(customer.customerId); record[2] = customer.fullName; data.add(record); } tModel = new TableModel(data); // In the above for loop accoring to user input (i.e click on check all or // uncheck all) i have tried to update the data. As it can be seen that i // have a condition for record[0]. //After the loop, here i have tried several options like validate(). repaint but to no avail customerTable = new JTable(tModel); scrollPane = new JScrollPane(customerTable); setContentPane(this.createContentPane()); setSize(480, 580); setResizable(false); setVisible(true); } private JPanel createContentPane() { custSelectPanel.setLayout(null); customerTable.setDragEnabled(false); customerTable.setFillsViewportHeight(true); scrollPane.setLocation(10, 10); scrollPane.setSize(450,450); custSelectPanel.add(scrollPane); buttonPanel.setLayout(null); buttonPanel.setLocation(10, 480); buttonPanel.setSize(450, 100); custSelectPanel.add(buttonPanel); selectAllButton.setLocation(0, 0); selectAllButton.setSize(100, 40); buttonPanel.add(selectAllButton); clearAllButton.setLocation(110, 0); clearAllButton.setSize(100, 40); buttonPanel.add(clearAllButton); applyButton.setLocation(240, 0); applyButton.setSize(100, 40); buttonPanel.add(applyButton); cancelButton.setLocation(350, 0); cancelButton.setSize(100, 40); buttonPanel.add(cancelButton); return custSelectPanel; } } Table Model private class TableModel extends AbstractTableModel { private List data; public TableModel(List data) { this.data = data; } private String[] columnNames = {"Selected ", "Customer Id ", "Customer Name " }; public int getColumnCount() { return COLUMN_COUNT; } public int getRowCount() { return data == null ? 0 : data.size(); } public String getColumnName(int col) { return columnNames[col]; } public void setValueAt(Object value, int rowIndex, int columnIndex) { getRecord(rowIndex)[columnIndex] = value; super.fireTableCellUpdated(rowIndex, columnIndex); } private Object[] getRecord(int rowIndex) { return (Object[]) data.get(rowIndex); } public Object getValueAt(int rowIndex, int columnIndex) { return getRecord(rowIndex)[columnIndex]; } public Class getColumnClass(int columnIndex) { if (data == null || data.size() == 0) { return Object.class; } Object o = getValueAt(0, columnIndex); return o == null ? Object.class : o.getClass(); } public boolean isCellEditable(int row, int col) { if (col > 0) { return false; } else { return true; } } } } A Views Action Listener class CustomerSelectorUIListener implements ActionListener{ CustomerSelectorDialogUI custSelectView; Controller controller; public CustomerSelectorUIListener (Controller controller, CustomerSelectorDialogUI custSelectView) { this.custSelectView = custSelectView; this.controller = controller; } @Override public void actionPerformed(ActionEvent e) { String actionEvent = e.getActionCommand(); else if ( actionEvent.equals( "clearAllButton" ) ) { controller.checkButtonControl(false); } else if ( actionEvent.equals( "selectAllButton" ) ) { controller.checkButtonControl(true); } } } Main Controller public class Controller implements ActionListener{ CustomerSelectorDialogUI selectUI; DummyCustomerStore store; public Controller( DummyCustomerStore store, TestApplicationUI appUI ) { this.store = store; this.appUI = appUI; appUI.ButtonListener( this ); } @Override public void actionPerformed(ActionEvent event) { String viewAction = event.getActionCommand(); if (viewAction.equals("TEST")) { selectUI = new CustomerSelectorDialogUI(appUI, store, true); selectUI.showTextActionListeners(new CustomerSelectorUIListener( this, selectUI ) ); selectUI.setVisible( true ); } } public void checkButtonControl (Boolean checkAll) { selectUI.PopulateAndShow(store, checkAll); } }

    Read the article

  • Auto-hide JMenuBar

    - by PeterMmm
    When i run the code above the frame's menu bar come up when the mouse moves to the upper part of the window. The problem is when i open the menu but do not select any item and move out the mouse the menu bar get invisible but the items stay on screen. public class Test extends JFrame { public Test() { setLayout(new BorderLayout()); setSize(300, 300); JMenuBar mb = new JMenuBar(); setJMenuBar(mb); mb.setVisible(false); JMenu menu = new JMenu("File"); mb.add(menu); menu.add(new JMenuItem("Item-1")); menu.add(new JMenuItem("Item-2")); addMouseMotionListener(new MouseAdapter() { @Override public void mouseMoved(MouseEvent e) { getJMenuBar().setVisible(e.getY() < 50); } }); } public static void main(String args[]) { new Test().setVisible(true); } }

    Read the article

  • Adding KeyListener to a JWindow not getting any key events

    - by Untitled
    Hello everyone, In Java, I am adding a KeyListener to a JWindow, but it is not getting any key events. If I used the same code but extend a JFrame instead, then everything works fine. public class MyWindow extends JWindow { ... ... private void initComponents() { ... ... addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { System.out.println("KEY PRESSED: " + e.getKeyCode()); } public void keyReleased(KeyEvent e) { System.out.println("KEY RELEASED: " + e.getKeyCode()); } public void keyTyped(KeyEvent e) { System.out.println("KEY TYPED: " + e.getKeyCode()); } }); } } Anyone know how can I solve this by using a JWindow? Please note that I am using Linux, so I am not sure if it is something to do with the platform. Thanks

    Read the article

  • Question about layout in java.

    - by extro
    I have two panels main_panel and child_panel. I have set layout for main_panel by using "main_panel.setLayout(flowlayout)" and added child_panel in main_panel by using "main_panel.add(child_panel)". This child_panel gets added to main_panel but its position is at the cross-section of horizontal midpoint and top vertical section of screen. But I want child_panel to be at the top left corner, something I could have done by using "child_panel.setlocation(a,b)" method, if I have set the Layout of main_panel as NULL. I have used flowlayout here because I want components in the JPanel to keep adjusting with the size of JFrame. So question is, can I add child_panel to main_panel at the exact location I want, even if I set the Layout of main_panel as not NULL.

    Read the article

  • Object can not be resolved.

    - by Gabriel A. Zorrilla
    I have this code: public class Window extends JFrame { public Window(){ ... JButton button = new JButton("OK"); getContentPane().add(button); ButtonHandler handler = new ButtonHandler(); button.addActionListener(handler); ... } private class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent event){ if (event.getSource() == button){ // <--- "button can not be resolved" System.out.println("Hello"); } } } I'm getting that error in Eclipse. I just made a (simplified) example found in a book, dont know what can be wrong. Knowledge eye required! :)

    Read the article

  • Jar File doesn't work (It did not launch the application)

    - by Mr CooL
    Previously, I have no problem in running the JAR file generated by NetBeans. However, I encountered the problem now all of a sudden. When I click on the jar, it did not launch the application as if nothing is clocked. But, it can be run from the project. And also, the size of the Jframe for desktop Java application cannot be set from the NetBeans code also. When it runs, the size of the window different from in the designer. Any help please.

    Read the article

  • Why a EDT violation happens?

    - by Roman
    I started to use CheckThreadViolationRepaintManager to detect EDT violations. It complains about: partner = getParameter("partner",generatePartnerSelectionPanel(),Design.partnerSelectionDuration); Because it does not like generatePartnerSelectionPanel() because it does not like JPanel panel = new JPanel(); in this method. But I cannot find out why there should be a problem around that. In more details, generatePartnerSelectionPanel() generates a JPanel (I do it not in the EDT) but then, in the getParameter I add the JPanel to the main JFrame and I do it in the EDT (using invokeLater). So, why there should be a problem?

    Read the article

  • Can you cast an object to one that implements an interface? (JAVA)

    - by DDP
    Can you cast an object to one that implements an interface? Right now, I'm building a GUI, and I don't want to rewrite the Confirm/Cancel code (A confirmation pop-up) over and over again. So, what I'm trying to do is write a class that gets passed the class it's used in and tells the class whether or not the user pressed Confirm or Cancel. The class always implements a certain interface. Code: class ConfirmFrame extends JFrame implements ActionListener { JButton confirm = new JButton("Confirm"); JButton cancel = new JButton("Cancel"); Object o; public ConfirmFrame(Object o) { // Irrelevant code here add(confirm); add(cancel); this.o = (/*What goes here?*/)o; } public void actionPerformed( ActionEvent evt) { o.actionPerformed(evt); } } I realize that I'm probably over-complicating things, but now that I've run across this, I really want to know if you can cast an object to another object that implements a certain interface.

    Read the article

  • How do I prevent my form from freezing when it is loading an image from the web at the click of a button?

    - by Vimal Basdeo
    I want to display an image from the web to a panel in another Jframe at the click of a button but whenever I click the button first the image loads and during this time the current form potentially freezes and once the image has loaded the form is displayed with the image.. How can I avoid the situation where my form freezes since it is very irritating My codes :: My current class private void btn_TrackbusActionPerformed(java.awt.event.ActionEvent evt) { try { sendMessage("Query,map,$,start,211,Arsenal,!"); System.out.println(receiveMessage()); } catch (UnknownHostException ex) { Logger.getLogger(client_Trackbus.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(client_Trackbus.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(client_Trackbus.class.getName()).log(Level.SEVERE, null, ex); } client_trackedbus nextform=new client_trackedbus(planform,connection,packet_receive,packet_send); this.setVisible(false); this.dispose(); nextform.setVisible(true); // TODO add your handling code here: } My next class that displays the image public class client_trackedbus extends javax.swing.JFrame { client_planform planform=null; DatagramSocket connection=null; DatagramPacket packet_receive=null; DatagramPacket packet_send=null; JLabel label=null; /** Creates new form client_trackedbus */ public client_trackedbus(client_planform planform,DatagramSocket connection,DatagramPacket packet_receive,DatagramPacket packet_send) { initComponents(); this.planform=planform; this.connection=connection; this.packet_receive=packet_receive; this.packet_send=packet_send; try { displayMap("http://www.huddletogether.com/projects/lightbox2/images/image-2.jpg", jPanel1, new JLabel()); } catch (MalformedURLException ex) { Logger.getLogger(client_trackedbus.class.getName()).log(Level.SEVERE, null, ex); } } private void displayMap(String url,JPanel panel,JLabel label) throws MalformedURLException{ URL imageurl=new URL(url); Image image=(Toolkit.getDefaultToolkit().createImage(imageurl)); ImageIcon icon = new ImageIcon(image); label.setIcon(icon); panel.add(label); // System.out.println(panel.getSize().width); this.getContentPane().add(panel); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); btn_Exit = new javax.swing.JButton(); btn_Plan = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Public Transport Journey Planner"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 368, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 172, Short.MAX_VALUE) ); jLabel1.setFont(new java.awt.Font("Arial", 1, 18)); jLabel1.setText("Your tracked bus"); btn_Exit.setText("Exit"); btn_Exit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btn_ExitActionPerformed(evt); } }); btn_Plan.setText("Plan journey"); btn_Plan.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btn_PlanActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(104, 104, 104) .addComponent(jLabel1)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(65, 65, 65) .addComponent(btn_Plan) .addGap(65, 65, 65) .addComponent(btn_Exit, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(20, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(35, 35, 35) .addComponent(jLabel1) .addGap(18, 18, 18) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btn_Exit) .addComponent(btn_Plan)) .addContainerGap(12, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void btn_ExitActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Exitform(); } private void btn_PlanActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: this.setVisible(false); this.dispose(); this.planform.setVisible(true); } private void Exitform(){ this.setVisible(false); this.dispose(); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { // new client_trackedbus().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btn_Exit; private javax.swing.JButton btn_Plan; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; // End of variables declaration }

    Read the article

  • Changing The Underlying Background Color Of A Swing Window

    - by dimo414
    As discussed here, when resizing a Swing application in Vista (and Windows 7, which is what I'm using) you get a black background in the right/bottom corner while Swing's repaint catches up to the changes. Playing with other applications (Windows Explorer (Native), Firefox (C++?), and Eclipse (Java)) I notice that they all have this same problem - contrary to what the folks in the link above say - but they minimize the problem by having a grey fill color, which is far less visually jarring than the black that appears in Swing. I'm wondering if there's some way to change this so that Swing behaves like these other applications? I tried setting the background color of the JFrame, but to no avail.

    Read the article

< Previous Page | 12 13 14 15 16 17 18 19 20  | Next Page >