Search Results

Search found 428 results on 18 pages for 'jpanel'.

Page 2/18 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Adding an unknown number of JComponents to a JPanel

    - by Matthew
    Good day, I am building an Applet (JApplet to be exact) and I sub divided that into two panels. The top panel is called DisplayPanel which is a custom class that extends JPanel. The bottom panel is called InputPanel which also extends JPanel. As mentioned above, I can add those two Panel's to the applet and they display fine. The next thing that I would like to do is have the InputPanel be able to hold a random number of JComponent Objects all listed veritcally. This means that the InputPanel should be able to have JButtons, JLabels, JTextFields etc thrown at it. I then want the InputPanel to display some sort of scrolling capability. The catch is that since these two panels are already inside my applet, I need the InputPanel to stay the same size as it was given when added to the Applet. So for example, if my applet (from the web-browser html code) was given the size 700,700, and then the DisplayPanel was 700 by 350, and the InputPanel was below it with the same dimensions, I want to then be able to add lots of JComponents like buttons, to the InputPanel and the panel would stay 700 x 350 in the same position that it is at, only the panel would have scroll bars if needed. I've played with many different combinations of JScrollPane, but just cannot get it. Thank you.

    Read the article

  • JPanel not listening to key event when there is a child component with JButton on it

    - by Yifu
    I'm working on a map editor for my college project. And I had a problem that the map panel is not listening key event while it should. This happens when I add a ToolBarPane (which extends JPanel) with JComponent such as JButton, JComboBox that implements ActionListener on it AND the map panel (which extends the JPanel) together on to the Frame (I used BorderLayout). I have System.out.println statement to test if the key press is received, and it's not printing, if I remove the ToolBar, the key listener works again, so is the mouseListenner is disabled just like the keyListener, which means I can't handle press events etc, but the mouseListener works fine and I can still handle mouse move event. Here is a screen shot how it works without the ToolBarPane http://img684.imageshack.us/img684/3232/sampleku.png note that you can use the mouse to put images on the map, you can also select images using the mouse just like a laser tool, and by pressing number key you can switch between different images, this works fine until I add the ToolBarPane which shows like this: img291.imageshack.us/img291/8020/failve.png (please add http before that, i can only post one hyperlink) (I can't post images here cuz im a new user) With the ToolBarPane on I was no longer able to handle the key event. I guess it might by that the focus as been transfered to that panel somehow, but not sure at all. Does and body know this and can help me out? Thanks very much

    Read the article

  • Using addMouseListener() and paintComponent() for JPanel

    - by Alex
    This is a follow-up to my previous question. I've simplified things as much as I could, and it still doesn't work! Although the good thing I got around using getGraphics(). A detailed explanation on what goes wrong here is massively appreciated. My suspicion is that something's wrong with the the way I used addMouseListener() method here. import java.awt.Color; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JFrame; import javax.swing.JPanel; public class MainClass1{ private static PaintClass22 inst2 = new PaintClass22(); public static void main(String args[]){ JFrame frame1 = new JFrame(); frame1.add(inst2); frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame1.setTitle("NewPaintToolbox"); frame1.setSize(200, 200); frame1.setLocationRelativeTo(null); frame1.setVisible(true); } } class PaintClass11 extends MouseAdapter{ int xvar; int yvar; static PaintClass22 inst1 = new PaintClass22(); public PaintClass11(){ inst1.addMouseListener(this); inst1.addMouseMotionListener(this); } @Override public void mouseClicked(MouseEvent arg0) { // TODO Auto-generated method stub xvar = arg0.getX(); yvar = arg0.getY(); inst1.return_paint(xvar, yvar); } } class PaintClass22 extends JPanel{ private static int varx; private static int vary; public void return_paint(int input1, int input2){ varx = input1; vary = input2; repaint(varx,vary,10,10); } public void paintComponent(Graphics g){ super.paintComponents(g); g.setColor(Color.RED); g.fillRect(varx, vary, 10, 10); } }

    Read the article

  • Custom JComponent not displaying in Custom JPanel

    - by Trizicus
    I've tried the add() method but nothing is displayed when I try to add Test to GraphicsTest. How should I be adding it? Can someone show me? I've included the code I'm using. import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JComponent; public class Test extends JComponent { Test() { setOpaque(false); setBackground(Color.white); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(Color.red); g2d.drawString("Hello", 50, 50); g2d.dispose(); } } import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.geom.Rectangle2D; import javax.swing.JPanel; public class GraphicsTest extends JPanel implements MouseListener { private Graphics2D g2d; private String state; private int x, y; GraphicsTest() { add(new Test()); } @Override public void paintComponent(Graphics g) { super.paintComponent(g); g2d = (Graphics2D) g; g2d.setColor(Color.BLACK); g2d.drawString("STATE: " + state, 5, 15); g2d.drawString("Mouse Position: " + x + ", " + y, 5, 30); g2d.setColor(Color.red); Rectangle2D r2d = new Rectangle2D.Double(x, y, 10, 10); g2d.draw(r2d); g2d.dispose(); } public void setState(String state) { this.state = state; } public String getState() { return state; } public void setX(int x) { this.x = x; repaint(); } public void setY(int y) { this.y = y; repaint(); } public void mouseClicked(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} }

    Read the article

  • JPanel in JFrame in NetBeans

    - by Gaurav
    I have created a Java application (project) in NetBeans, in which I have designed a JFrame with menu bar, and different JPanels. I want these JPanels to appear inside the JFrame on action of different menu items, so that whenever the menu items are clicked different JPanels should appear inside the JFrame. I have designed both JFrame & JPanel separately, but I couldn't link them together. Please help me out friends.

    Read the article

  • Revalidate JPanel's parent frame

    - by Tom Brito
    I need show/hide some fields of my panel, and I want the panel to fit the frame. How could I notify to the parent frame to revalidate? I think in pass the frame to my panel's constructor, but I think may have a way this is already done. I remember that there was a protected attribute in JPanel, but there isn't.. maybe i remembering the wrong component.

    Read the article

  • How to set a Transparent Background of JPanel

    - by Imran
    Hi, I need to know if a JPanel`s bacground can be set to Transparent? My frame is has two Jpanels Image Panel and Feature Panel, Feature Panel is overlapping Image Panel, the Image Panel is working as a background and it is loading image from a remote Url, now I want to draw shaps on Feature Panel , but now Image Panel cannot be seen due to Feature Panel's background color. I need to make Feature Panel background transparent while still drawing its shapes and i want Image Panel to be visible since it is doing tiling and cache function of images. I need to seperate the image drawing and shape drawing thats why I`m using two jPanels! is there anyway the overlapping Jpanel have a transparent background? thanks

    Read the article

  • Get two Jpanel expand in a JFrame asymmetrically.

    - by Gabriel A. Zorrilla
    Hi there. I have a JFrame with two JPanels inside. One is set on west, other on east with BorderLayout. The thing is, it just shows two 10 pixel width, 100% JFrame height strips: What i want to do is to setsize each panel having as end result that the jpanel on the west be 80% of the jframe width, the remaining 20% to the one on the east. Is it possible? Should I use another layout? Thanks a lot.

    Read the article

  • JPanel on top of JLabel

    - by newbie
    Good day! Is it possible to add a JPanel on top of a JLabel? I would like my JFrame to have a background image and in order to this, i used this code (based from past stackoverflow answers): setLocation(150,50); setSize(700,650); setVisible(true); JLabel contentPane = new JLabel(); contentPane.setIcon(new ImageIcon("pics/b1.jpg")); contentPane.setLayout( new BorderLayout()); setContentPane( contentPane ); Now my problem is, I cannot put a panel on my JFrame because of the JLabel background. Please help. Thanks.

    Read the article

  • More than one JPanel in a Frame / having a brackground Image and another Layer with Components on the top

    - by user1905203
    I've got a JFrame with a JPanel in which there is a JLabel with an ImageIcon(). Everything's working perfectly, problem is i now want to add another JPanel with all the other stuff like buttons and so on to the JFrame. But it still shows the background Image on top and nothing with the second JPanel. Can someone help me? Here is an extract of my code: JFrame window = new JFrame("Http Download"); /* * Background Section */ JPanel panel1 = new JPanel(); JLabel lbl1 = new JLabel(); /* * Component Section */ JPanel panel2 = new JPanel(); JLabel lbl2 = new JLabel(); /* * Dimension Section */ Dimension windowSize = new Dimension(800, 600); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); public HTTPDownloadGUI() { window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); panel1.setLayout(null); panel1.setSize(windowSize); panel1.setOpaque(false); panel2.setLayout(null); panel2.setSize(windowSize); panel2.setOpaque(false); lbl1.setSize(windowSize); lbl1.setLocation(0, 0); lbl1.setIcon(new ImageIcon(getClass().getResource("bg1.png"))); panel1.add(lbl1); lbl2.setBounds(0, 0, 100, 100); //lbl2.setIcon(new ImageIcon(getClass().getResource("bg2.png"))); lbl2.setBackground(Color.GREEN); panel2.add(lbl2); panel1.add(panel2); window.add(panel1); int X = (screen.width / 2) - (windowSize.width / 2); int Y = (screen.height / 2) - (windowSize.height / 2); window.setBounds(X,Y , windowSize.width, windowSize.height); window.setVisible(true); }

    Read the article

  • Detecting mouse enter/exit events anywhere on JPanel

    - by Mano
    Hi, Basically there is a JPanel on which I want to know when the mouse enters the area of the JPanel and exits the area of the JPanel. So I added a mouse listener, but if there are components on the JPanel and the mouse goes over one of them it is detected as an exit on the JPanel, even though the component is on the JPanel. I was wondering whether anyone knows any way to solve this problem without doing something like adding listeners onto all components on the JPanel?

    Read the article

  • JPanel superclass doesn't add the components of its subclasses..

    - by Acryl
    Well, I use a JFrame that adds two JPanels. Those JPanels are superclasses, because I find it easier to separate different areas of the GUI into different classes. But here's the problem: I add the (superclass) JPanel to the JFrame I set the layout of the superclass JPanel to new BorderLayout(); I add components in the subclasses, like this: JPanel panel = new JPanel(); panel.setLayout(new GridLayout(2,1)); panel.add(new JLabel("Label:"); panel.add(new JTextField(); add(panel, BorderLayout.NORTH); But it doesn't show. What do I do wrong? I've tried it without an additional JPanel in the subclasses, but it doesn't work either. I use jdk 1.6

    Read the article

  • How to put JFrame into existing JPanel in Java Swing?

    - by suud
    I have an open-source java swing application like this: http://i47.tinypic.com/dff4f7.jpg You can see in the screenshot, there is a JPanel divided into two area, left and right area. The left area has many text links. When I click the SLA Criteria link, it will pop-up the SLA Criteria window. The pop-up window is JFrame object. Now, I'm trying to put the pop-up window into right area of the JPanel, so that means no pop-up window anymore, i.e. when I click the SLA Criteria link, its contents will be displayed at the right area of the JPanel. The existing content of the right area of JPanel will not be used anymore. The example illustration (note: it's made and edited using image editor, this is not the real screenshot of working application) is like this: http://i48.tinypic.com/5vrxaa.jpg So, I would like to know is there a way to put JFrame into JPanel? I'm thinking of using JInternalFrame, is it possible? Or is there another way? UPDATE: Source code: http://pastebin.com/tiqRbWP8 (VTreePanel.java, this is the JPanel) http://pastebin.com/330z3yuT (CPanel.java, this is the super class of VTreePanel) http://pastebin.com/MkNsbtjh (AWindow.java, this is the JFrame, pop-up window) http://pastebin.com/2rsppQeE (CFrame.java, this is the super class of AWindow)

    Read the article

  • adding jpanel into a jframe. netbeans

    - by stdnoit
    i am particularly using netbeans gui editor and i am new to gui i have a jframe created and I added jtabbedpanel. inside the jtabbedpanel i have 2 panels that i call standard and compact i have set standardPanel = new ImagePanel(); which ImagePanel.java is located on different java file how am I suppose to put a panel on different file for reusability ? i obviously dont want all the codes in a single file. is this the right way to design a gui ? thanks

    Read the article

  • JPanel background image

    - by Zloy Smiertniy
    This is my code, it indeed finds the image so that is not my concern, my concern is how to make that image be the background of the panel. I'm trying to work with Graphics but i doesnt work, any ideas?? please?? try { java.net.URL imgURL = MAINWINDOW.class.getResource(imagen); Image imgFondo = javax.imageio.ImageIO.read(imgURL); if (imgFondo != null) { Graphics grafica=null; grafica.drawImage(imgFondo, 0, 0, this); panel.paintComponents(grafica); } else { System.err.println("Couldn't find file: " + imagen); } } catch...

    Read the article

  • Removing JPanel from a JFrame in netbeans

    - by jt153
    So, I have several JPanels that contain buttons, labels, etc. that I want to switch between from a main JFrame. Currently I am trying to use the this.add(JPanelname); method and this.remove(JPanelname); with the validate(); and repaint(); methods The problem is it will add the panel to the JFrame but it will not remove it. I am not sure how exactly to go about this and any help would be greatly appreciated.

    Read the article

  • How can I fade in a JPanel & children?

    - by Christian 'fuzi' Orgler
    I know that I can fade in a panel, by adding the alpha value to the background color & a timer. But how can I fade in a panel with child components (like a JLabel)? EDIT _fadeTimer = new Timer(40, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (_alpha == 255) { _fadeTimer.stop(); } else { pnl_hint.setBackground(new Color( bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), (_alpha += 1))); pnl_hint.updateUI(); } } }); _fadeTimer.start();

    Read the article

  • Resizing JPanel to prepare for printing without removing it from its original position

    - by Lesman
    In my program I frequently need to print various JComponents (generally JPanels) and I like them to be full-page. The way I do it now is by using the following code: g2d.scale(pf.getImageableWidth()/componentToPrint.getWidth(), pf.getImageableHeight()/componentToPrint.getHeight()); but this often stretches or otherwise deforms whatever I am trying to print, and I would much prefer to do something that re-sized intelligently, perhaps a functional version of: componentToPrint.setSize(pf.ImageableWidth(), pf.ImageableHeight); or say adding the component into a new JFrame and then setting the frame size (problem is components can't exist in two place at once). I wouldn't care if the resizing would make the rest of the GUI look terrible, as long as it is something that can easily be reset. Is there any way to do this?

    Read the article

  • Transparent JPanel, Canvas background in JFrame

    - by Andy Tyurin
    I wanna make canvas background and add some elements on top of it. For this goal I made JPanel as transparent container with setOpaque(false) and added it as first of JFrame container, then I added canvas with black background (in future I wanna set animation) to JFrame as second element. But I can't undestand why i see grey background, not a black. Any suggestions? public class Game extends JFrame { public Container container; //Game container with components public Canvas backgroundLayer; //Background layer of a game public JPanel elementsLayer; //elements panel (top of backgroundLayer), holds different elements private Dimension startGameDimension = new Dimension(800,600); //start game dimension public Game() { //init main window super("Astra LaserForces"); setSize(startGameDimension); setBackground(Color.CYAN); container=getContentPane(); container.setLayout(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //init jpanel elements layer elementsLayer=new JPanel(); elementsLayer.setSize(startGameDimension); elementsLayer.setBackground(Color.BLUE); elementsLayer.setOpaque(false); container.add(elementsLayer); //init canvas background layer backgroundLayer = new Canvas(); backgroundLayer.setSize(startGameDimension); backgroundLayer.setBackground(Color.BLACK); //set default black color container.add(backgroundLayer); } //start game public void start() { setVisible(true); } //create new instance of game and start it public static void main(String[] args) { new Game().start(); } }

    Read the article

  • Question about JPanel "transition" for Java Swing

    - by user16778
    I want to make like a sort of main menu (in GUI). When the user clicks the start button, the screen transition into another "screen" (JPanel). This image will make it easier to understand. http://i.imgur.com/Cfdry.png Currently, I have a MainMenu extends JPanel and that gets added into a driver class with a JFrame. I can't figure how to switch to another class like Game extends JPanel. So when the user clicks the start button in MainMenu, I want it to somehow hide itself and the Game to show itself. Thanks.

    Read the article

  • Java Swing: how to add an image to a JPanel ?

    - by Leonel
    I have a JPanel to which I'd like to add JPEG and PNG images that I generate on the fly. All the examples I've seen so far in the Swing Tutorials, specially in the Swing examples use ImageIcons. I'm generating these images as byte arrays, and they are usually larger than the common icon they use in the examples, at 640x480. Is there any (performance or other) problem in using the ImageIcon class to display an image that size in a JPanel ? What's the usual way of doing it ? How to add an image to a JPanel without using the ImageIcon class ? Edit: A more careful examination of the tutorials and the API shows that you cannot add an ImageIcon directly to a JPanel. Instead, they achieve the same effect by setting the image as an icon of a JLabel. This just doesn't fill right...

    Read the article

  • Can't remove JPanel from JFrame while adding new class into it

    - by A.K.
    Basically, I have my Frame class, which instantiates all the properties for the JFrame, and draws a JLabel with an image (my title screen). Then I made a separate JPanel with a start button on it, and made a mouse listener that will allow me to remove these objects while adding in a new Board() class (Which paints the main game). *Note: The JLabel is SEPARATE from the JPanel, but it still gets moved to the side by it. Problem: Whenever I click the button though, it only shows a little square of what I presume is my board class trying to run. Code below for the Frame Class: package OurPackage; //Made By A.K. 5/24/12 //Contains Frame. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.Image; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.*; import javax.swing.plaf.basic.BasicOptionPaneUI.ButtonActionListener; public class Frame implements MouseListener { public static boolean StartGame = false; ImageIcon img = new ImageIcon(getClass().getResource("/Images/ActionJackTitle.png")); ImageIcon StartImg = new ImageIcon(getClass().getResource("/Images/JackStart.png")); public Image Title; JLabel TitleL = new JLabel(img); public JPanel panel = new JPanel(); JButton StartB = new JButton(StartImg); JFrame frm = new JFrame("Action-Packed Jack"); public Frame() { TitleL.setPreferredSize(new Dimension(1200, 420)); frm.add(TitleL); frm.setLayout(new GridBagLayout()); frm.add(panel); panel.setSize(new Dimension(220, 45)); panel.setLayout(new GridBagLayout ()); panel.add(StartB); StartB.addMouseListener(this); StartB.setPreferredSize(new Dimension(220, 45)); frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frm.setSize(1200, 420); frm.setVisible(true); frm.setResizable(false); frm.setLocationRelativeTo(null); } public static void main(String[] args) { new Frame(); } public void mouseClicked(MouseEvent e) { StartB.setContentAreaFilled(false); panel.remove(StartB); frm.remove(panel); frm.remove(TitleL); //frm.setLayout(null); frm.add(new Board()); //Add Game "Tiles" Or Content. x = 1200 frm.validate(); System.out.println("Hit!"); } @Override public void mouseEntered(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseExited(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mousePressed(MouseEvent arg0) { // TODO Auto-generated method stub } @Override public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated method stub } }

    Read the article

  • How do I remove an old JPanel and add a new one?

    - by Roman
    I would like to remove an old JPanel from the Window (JFrame) and add a new one. How should I do it? I tried the following: public static void showGUI() { JFrame frame = new JFrame("Colored Trails"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(partnerSelectionPanel); frame.setSize(600,400); frame.setVisible(true); } private static void updateGUI(final int i, final JLabel label, final JPanel partnerSelectionPanel) { SwingUtilities.invokeLater( new Runnable() { public void run() { label.setText(i + " seconds left."); } partnerSelectionPanel.setVisible(false); \\ <------------ } ); } So, my code update the "old" JPanel and them it makes the whole JPanel invisible. It was the idea. But it does not work. The compiler complains about the line indicated with "<------------". It writes: <identifier> expected, illegal start of type.

    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

  • all individual panels are not shown inside root panel

    - by Suresh Kumar
    Respected sir/madam, I want to add multiple jpanels to jpanel.So i added a root panel to jscrollpane.and then added all individual jpanels to this root panel.I made jscrollpane's scrolling policy as needed.i.e HORIZONTAL_SCROLLBAR_AS_NEEDED,VERTICAL_SCROLLBAR_AS_NEEDED. But the problem is all individual panels are not shown inside root panel. Code: JScrollPane scPanel=new JScrollPane(); JPanel rootPanel=new JPanel(); rootPanel.setLayout(new FlowLayout()); JPanel indPanel = new JPanel(); rootPanel.add(indPanel); JPanel indPanel2 = new JPanel(); rootPanel.add(indPanel2); //.....like this added indPanals to rootPanel. scPanel.setViewPortView(rootPanel); //scPanel.setHorizontalScrollPolicy(HORIZONTAL_SCROLLBAR_AS_NEEDED); And one more thing is, as i scroll the scrollbar the panels are going out of jscrollpane area. I am not able to see all individual panels, Please suggest me.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >