Search Results

Search found 37239 results on 1490 pages for 'javax swing text'.

Page 12/1490 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • swing: event listener support class

    - by Jason S
    Is there any preexisting class that helps support add/remove EventListener operations? (kind of like PropertyChangeSupport) I'm trying to partition my code into a model and view in Java. I have some data that arrives erratically, and would like the model to support some kind of EventListener so that a view can subscribe to changes in the model. The data is numerous + complicated enough that I don't want to have to do the whole fine-grained Javabeans property change support; rather I would just like to allow notification that the model has changed in a coarse way. how can I best do this?

    Read the article

  • Java Swing custom shapes (2D Graphics)

    - by juFo
    I need to draw custom shapes. Now when a user clicks on several points on the panel I create a shape using a polygon. public void mouseClicked(MouseEvent e) { polygon.addPoint(e.getX(), e.getY()); repaint(); } But I don't know if this is the best way to draw custom shapes. It should be possible to edit a drawn shape: resize change its fill color change the stroke color copy/paste it move a single point of the polygon ... I have seen people creating an own class implementing the Shape class and using a GeneralPath. But again I have no idea if this is a good way. Now I can create my own shape with a polygon (or with a GeneralPath) but I have no clue how to attach all the edit functions to my own shape (the edit functions I mean the resize, move, etc from above). I hope somebody could show me a way to do this or maybe write a little bit of code to demonstrate this. Thanks in advance!!

    Read the article

  • How to do animation using swing and clojure ?

    - by Humberto Pinheiro
    I'm trying to animate a chess piece in a board. First I created a java.util.Timer object that "scheduleAtFixedRate" a TimerTask implemented as a proxy function. So I kept a record of the piece to move (piece-moving-record) and when it's apropriate (when the user move the piece using the mouse) the TimerTask proxy function should be test if the record is not nil and execute the piece-moving function. The piece-moving function just updates the x and y coordinates of the piece, according to a vector pre-calculated. I put a add-watch on the piece-moving-record so when it changes it should repaint the board (canvas). The paint method tests if this piece-moving-record is not nil to paint it. The problem is that the animation doesn't appear. The piece just jump to the destiny, without the movement between. There is some problem with the animation scheme ou there is a better way to do it?

    Read the article

  • Java Swing - Adding a row # column (row header) to a JTable

    - by llm
    I have data from a database loaded into a JTable through a custom table model. I want to have a column (should be the first column) which simply shows the display row number (i.e. it is not tied to any data (or sorting) but is simply the row number on the screen starting at 1). These "row headers" should be grayed out like the row headers. Any idea how to do this? Thanks

    Read the article

  • Not sure why I'm getting a NullPointerException when creating a Swing component

    - by Alex
    The error occurs when creating the Box object. public void drawBoard(Board board){ for(int row = 0; row < 8; row++){ for(int col = 0; col < 8; col++){ Box box = new Box(board.getSquare(col, row).getColour(), col, row); squarePanel[col][row].add(box); } } Board is given from the Game constructor here (another class): public Game() throws Throwable{ View graphics = new View(); board = new Board(); board.setDefault(); graphics.drawBoard(board); } The Board constructor looks like this: public Board(){ grid = new Square[COLUMNS][ROWS]; for(int row = 0; row < 8; row++){ for(int col = 0; col < 8; col++){ grid[col][row] = new Square(this); } } for(int row = 0; row < 8; row++){ for(int col = 0; col < 4; col++){ int odd = 2*col + 1; int even = 2*col; getSquare(odd, row).setColour(Color.BLACK); getSquare(even, row).setColour(Color.WHITE); } } } And finally the Box class: class Box extends JComponent{ Color boxColour; int col, row; public Box(Color boxColour, int col, int row){ this.boxColour = boxColour; this.col = col; this.row = row; repaint(); } public void paint(Graphics drawBox){ drawBox.setColor(boxColour); drawBox.drawRect(50*col, 50*row, 50, 50); drawBox.fillRect(50*col, 50*row, 50, 50); } } So while looping through the array, it uses the two integers as coordinates to create the Box. The coordinates are referenced and then repaint() is run. The box also gets the colour, using the two integers, from the Square in the Board class. Since the colour is already set, before the drawBoard(board) method is run, that shouldn't be a problem, right? Exception in thread "main" java.lang.NullPointerException at View.drawBoard(View.java:38) at Game.<init>(Game.java:21) at Game.main(Game.java:14) The relevant part of Square import java.awt.Color; public class Square { private Piece piece; private Board board; private Color squareColour; public Square(Board board){ this.board = board; } public void setColour(Color squareColour){ this.squareColour = squareColour; } public Color getColour(){ return squareColour; }

    Read the article

  • Java Swing popup visibility

    - by Octavio
    Why a popup created like this is shown in front of all windows applications with JRE 1.6.0_18 but it doesn't using 1.6.0_03 ? PopupFactory popupFactory = new PopupFactory(); Popup popup= popupFactory.getPopup(null,new JPanel(),200,200); popup.show();

    Read the article

  • Java/Swing: Problem with key listener

    - by Mike
    I have a search dialog with a JTextField that's being used as a search box. When the user types something, it searches the DB, shows the result in a JTable and selects the first item in it. If the first result is what they were looking for, I want to let them quickly accept the dialog, by pressing Enter (while the JTextField is focused). So I added a KeyListener to the JTextField and it's working OK. Now the problem: The user opens can open the dialog by pressing Enter when a "Search" button on the dialog's parent frame is focused. The dialog is displayed and the JTextField gets the keyReleased event (from the Enter key that displayed it), so it shows up and closes. If the user holds Enter down, then the JTextField receives the keyPressed, keyTyped and keyReleased events. How can I fix without resorting to ugly workarounds? Platform is Windows 7 x64, btw. Test NetBeans project here: http://dl.dropbox.com/u/6354360/KeyListenerTest.zip Thanks.

    Read the article

  • Lines don't overlap when they should Java Swing

    - by Sven
    I'm drawing lines in a JFrame on a self made gridPanel. Problem is, I draw the lines between 2 points. When I have a line that is between point 1 and point 2 and a line between point 2 and point 3, the lines should connect. This however isn,t the case, there is a small gap in between, no idea why. But it isn't drawing till the end of the specified point. (start point is correct.) Here is the code of the JFrame: public void initialize(){ this.setLayout(new BorderLayout()); this.setPreferredSize(new Dimension(500, 400)); gridPane = new GridPane(); gridPane.setBackground(Color.WHITE); gridPane.setSize(this.getPreferredSize()); gridPane.setLocation(0, 0); this.add(gridPane,BorderLayout.CENTER); //createSampleLabyrinth(); drawWall(0,5,40,5); //These are the 2 lines that don't connect. drawWall(40,5,80,5); this.pack(); } drawWall calls a method that calls a method in GridPane. The relevant code in gridPane: /** * Draws a wall on this pane. With the starting point being x1, y1 and its end x2,y2. * @param x1 * @param y1 * @param x2 * @param y2 */ public void drawWall(int x1, int y1, int x2, int y2) { Wall wall = new Wall(x1,y1,x2,y2, true); wall.drawGraphic(); wall.setLocation(x1, y1); wall.setSize(10000,10000); this.add(wall, JLayeredPane.DEFAULT_LAYER); this.repaint(); } This method creates a wall and puts it in the Jframe. The relevant code of the wall: public class Wall extends JPanel { private int x1; private int x2; private int y1; private int y2; private boolean black; /** * x1,y1 is the start point of the wall (line) end is x2,y2 * * @param x1 * @param y1 * @param x2 * @param y2 */ public Wall(int x1, int y1, int x2, int y2, boolean black) { this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2; this.black = black; setOpaque(false); } private static final long serialVersionUID = 1L; public void drawGraphic() { repaint(); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; if(black){ g2.setColor(Color.BLACK); g2.setStroke(new BasicStroke(8)); } else { g2.setColor(Color.YELLOW); g2.setStroke(new BasicStroke(3)); } g2.drawLine(x1, y1, x2, y2); } } So, where am I going wrong? The true/false is to determine if the wall should be black or yellow, nothing to be concerned about.

    Read the article

  • Java Swing - How to disable a JPanel?

    - by Yatendra Goel
    I have several JComponents on a JPanel and I want to disable all of those components when I press a Start button. At present, I am disabling all of the components explicitly by component1.setEnabled(false); : : But Is there anyway by which I can disable all of the components at once? I tried to disable the JPanel to which these components are added by panel.setEnabled(false); but it didn't work.

    Read the article

  • Java/Swing: low-profile button height?

    - by Jason S
    I would like to reduce the vertical size of a JButton. The following code works fine for K 1 but I can't seem to reduce the size. Any suggestions? JButton button = /* ... get button here ... */ Dimension d = button.getPreferredSize(); d.setSize(d.getWidth(), d.getHeight()*K); button.setPreferredSize(d);

    Read the article

  • Java's Swing Threading

    - by nevets1219
    My understanding is that if I start up another thread to perform some actions, I would need to SwingUtilities.invokeAndWait or SwingUtilities.invokeLater to update the GUI while I'm in said thread. Please correct me if I'm wrong. What I'm trying to accomplish is relatively straightforward: when the user clicks submit, I want to (before performing any actions) disable the submit button, perform the action, and at the end of the action re-enable the button. My method to perform the action updates the GUI directly (displays results) when it gets the results back. This action basically queries a server and gets some results back. What I have so far is: boolean isRunning = false; synchronized handleButtonClick() { if ( isRunning == false ) { button.setEnabled( false ); isRunning = true; doAction(); } } doAction() { new Thread() { try { doAction(); // Concern A } catch ( ... ) { displayStackTrace( ... ); // Concern B } finally { SwingUtilities.invokeLater ( /* simple Runnable to enable button */ ); isRunning = false; } } } For both of my concerns above, do I would have to use SwingUtilities.invokeAndWait since they both will update the GUI? All GUI updates revolve around updating JTextPane. Do I need to in my thread check if I'm on EDT and if so I can call my code (regardless of whether it updates the GUI or not) and NOT use SwingUtilities.invokeAndWait?

    Read the article

  • Swing: set JFrame content area size

    - by igul222
    I'm trying to make a JFrame with a usable content area of exactly 500x500. If I do this... public MyFrame() { super("Hello, world!"); setSize(500,500); } ... I get a window whose full size is 500x500, including the title bar, etc., where I really need a window whose size is something like 504x520 to account for the window border and titlebar. How can I achieve this?

    Read the article

  • Line by line image swing

    - by user1046017
    I want to show an image as it is downloading, I have the URL, and I am trying to get the image parts like this: InputStream openStream = url.openStream(); DataInputStream dis = new DataInputStream(new BufferedInputStream(openStream)); ByteArrayOutputStream os = new ByteArrayOutputStream(); while ((s = dis.read(b)) != -1) { os.write(b , 0, s); support.firePropertyChange("stream", null, os); } This way, any listener get the stream and creates an image, this way: if("stream".equals(evt.getPropertyName())){ try { ByteArrayOutputStream stream = (ByteArrayOutputStream) evt.getNewValue(); byte[] byteArray = stream.toByteArray(); stream.flush(); Image createImage = Toolkit.getDefaultToolkit().createImage(byteArray); this.getContentPane().add(new JLabel(new ImageIcon(createImage))); } catch (IOException ex) { Logger.getLogger(ImageTest.class.getName()).log(Level.SEVERE, null, ex); } } However, I am getting a "Premature end of JPEG file sun.awt.image.ImageFormatException: JPEG datastream contains no image" error, the image is a JPG image format, is there any library or method known to make something similar?

    Read the article

  • java Swing Listeners: components listening at each others.

    - by Pierre
    Hi all, I want to code two JList (categories and items). When I click one category it should select all the items for that category and when I click on one item it should select its categories. So both JList will have a ListSelectionListener listening at each other and changing the selection. Should I fear about some a of "loop" ? Is there a way to tell that an Event has been consumed ? how do people manage that kind of situation ? Thanks

    Read the article

  • Need Java Swing equivalent of "scrollIntoView" from Browser DOM

    - by bgould
    I have a JPanel with several levels of child components, also with a JScrollPane. I'm placing a focus listener on some of the child components to add some behavior to those components, but I would also like to have that component scroll into the JPanel's viewport when focus is gained. My question is, does anyone have a general purpose function to do this, similar to the browser DOM function "scrollIntoView"? I've tried muddling through this with various inputs to JComponent.scrollRectToVisible but I guess I haven't figured out the magic word. Thanks in advance.

    Read the article

  • swing root pane

    - by xdevel2000
    I understood that every top level container has some layers: root pane layer pane content pane glass pane but I didn't understand if the root pane is the top level container itself...

    Read the article

  • Avoid Circular Reference in Swing GUI

    - by drhorrible
    Maybe it's not worth worrying about in this scenario, but lets say you have two classes, a JFrame with all its components, and a server-like class that handles requests from remote clients. The user is able to start and stop server objects through the GUI, and is shown various events that happen to each server object. Whether or not I use an explicit pattern (like MVC), it seems like the JFrame needs a reference to the server class (to call start and stop) and the server needs a reference to the JFrame (to notify of it of certain events). Is this a problem, or am I looking at this situation in the wrong way?

    Read the article

  • Swing: Multiple CellEditors for a column

    - by Luhar
    Hi, In my JTable, I have two editable numeric columns. The editor for both columns extends AbstractCellEditor and uses a JFormattedTextField as an the editing component. The problem is that the format for input depends on the value of another column in the row. If condition X is met, the number of fraction digits should be Y, otherwise they should be Y+2. I attempted to override the getTableCellEditor(..) method to associate a TableCellEditor per row. See this example. However, since I have two editable columns, sharing a single TableCellEditor object per row gives some very odd results. I don't think this is an appropriate solution. Any ideas on how to approach this would be much appreciated! Thank you!

    Read the article

  • Problem using FormLayout in Swing

    - by Dimitri
    Hi I am using the FormLayout. I just discovered it and it's powerful layout manager. I would like to layout 4 components (outlined, properties, tgraph, library) in 3 columns. I want to layout my library component on top of the outlined component in one column, the graph and the properties component in one column. But it doesn't work. Maybe I miss something. Here is my code : private void layoutComponent() { JPanel panel = new JPanel(); FormLayout layout = new FormLayout( "right:p,10dlu,300dlu,left:max(50dlu;p)", "top:pref,center:p,p"); layout.setRowGroups(new int[][]{{1,3}}); PanelBuilder builder = new PanelBuilder(layout,panel); builder.setDefaultDialogBorder(); CellConstraints constraints = new CellConstraints(); builder.add(library, constraints.xy(1, 1)); builder.add(outline,constraints.xy(1, 3)); builder.add(tgraph,constraints.xy(3, 1)); builder.add(properties,constraints.xy(4, 1)); getContentPane().add(panel);r code here } Can someone help plz. Thx :)

    Read the article

  • Revalidate and repaint - Java Swing

    - by bosra
    I have a JPanel that I am adding JLabel's to. I then want to remove all the JLabels and add some new ones. So I do the following: panel.removeAll();panel.repaint(); panel.add(new JLabel("Add something new"); panel.revalidate(); This works fine. My problem arises when I start a new thread after this like: panel.removeAll();panel.repaint(); (1)panel.add(new JLabel("Add something new"); panel.revalidate(); //new thread to start - this thread creates new JLabels that should appear under (1) firstProducer.start(); try { firstProducer.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } Then the output from the original JLabels is still visible. I have read that the revalidate process is a long running task and hence the firstProducer thread is getting started while the revalidation is going on and a conflict is arising. What is the best way to deal with this?

    Read the article

  • Java Swing - Adding a row # column to a JTable

    - by llm
    I have data from a database loaded into a JTable through a custom table model. I want to have a column (should be the first column) which simply shows the display row number (i.e. it is not tied to any data (or sorting) but is simply the row number on the screen starting at 1). These "column headers" should be grayed out like the row headers. Any idea how to do this? Thanks

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >