jpanel

Make a JPanel border with title like in Firefox

筅森魡賤 提交于 2019-12-01 15:31:17
问题 I would like to make an option dialog in my application. In this dialog I want to make kind of Areas surrounded with a border and with a title. An example of what I want is in Firefox: How can I do something like that in Java? 回答1: Here you can find all informations you need. Basically you can use border factory to create a Border using types available in Swing: Border lineBorder = BorderFactory.createLineBorder(Color.black); JPanel panel = new JPanel(); panel.setBorder(lineBorder); You can

How can I get all the components of a panel in Java Swing?

喜你入骨 提交于 2019-12-01 14:56:44
问题 How can I get all the components of a panel in Java Swing? Is there any method like foreach in C# to deal all the child components of a JPanel? 回答1: You may use the method getComponents: Component[] components = jpanel.getComponents(); 来源: https://stackoverflow.com/questions/15727661/how-can-i-get-all-the-components-of-a-panel-in-java-swing

JFrame, JPanel, paintComponent how to

一世执手 提交于 2019-12-01 14:36:41
Hi I have following classes, I want display content (paintComponentor that panel with this rectangle from paint class) inside my JFrame. I try already find out how to achieve this by looking at different examples posted on this forum however this doesn't help me I need simple example like panel inside frame with paint component or something similar to understand how should work! ps. don't hang me on tree because I am newbie jut ask question!!! [I want something like this][1] package scp; import java.awt.*; import javax.swing.*; public class Panel extends JPanel { public Panel() { //this

Implementing CardLayout within a JFrame and switching cards based on specific button presses

℡╲_俬逩灬. 提交于 2019-12-01 14:14:49
I've posted my code below. I have the simple task of creating a navigable GUI. I've spent the past few hours doing research on how to accomplish this, and this is the code that I've put together. Originally I wanted to perform the navigation without any layouts or anything. I need the home panel to display after the user clicks on the "login" button on the welcome panel. It displays the welcome card just fine, but when I get to the validateLogin method(which is activated when the login button is press, and upon successful login it should show the home panel within cards) it simply stays on the

How to change images based on keystrokes

浪子不回头ぞ 提交于 2019-12-01 14:08:07
I'm creating a program for a school project. It is a fan based program of Pokémon and I am having a little trouble understanding how to change images based on the key strokes. Here is the code so far for the Character Class import java.awt.Image; import java.awt.event.KeyEvent; import java.io.*; //the File class import java.util.*; //the Scanner class import javax.swing.ImageIcon; import javax.swing.JPanel; import java.awt.image.*; import javax.swing.ImageIcon; public class MainCharacter { private Image up, up1, up2, down, down1, down2, left, left1, left2, right, right1, right2; private void

Component on JPanel not showing when setLayout(null)

坚强是说给别人听的谎言 提交于 2019-12-01 13:39:20
Someone can tell why the combobox is not showing ? I have a Controller: public class TestController extends JPanel { TestView cgView; public TestController() { setLayout(null); cgView=new TestView(); add(cgView); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame fr = new JFrame("testt"); fr.setSize(1200,1000); fr.setResizable(false); TestController cgc=new TestController(); fr.setBackground(Color.white); fr.setVisible(true); fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fr.add(cgc); } }); } } And a view public class TestView

Multiple animations(threads) in a JPanel

拈花ヽ惹草 提交于 2019-12-01 13:29:31
I am trying to code a board game in Java. I have 11 classes including Main. Board class which extends JPanel and draws the board image as well as the dice image. The class Player which extends JCoponent and implements Runnable(Thread). Every player instance is a pawn-animation that it is moving across the board. The player class draws the pawn on the board. Pattern How the code it looks like : Board b=new Board(); Player p=new Player(); b.add(p); JPanel panel=new JPanel(); panel.add(b); add(panel); //adding the panel to the frame. The problem is that I can't have more than one pawn

Making a single component full screen

眉间皱痕 提交于 2019-12-01 13:25:28
I'm trying to make a JPanel go full screen when you click a button, and back again when you press escape. I've managed to get the window to go full screen, but because of the whole thing about adding components removing them from other containers, I end up with a blank JPanel. I chose to make a separate JFrame to render full screen, the class of which is as follows (note that this is an inner class, so myPanel refers to a panel that already exists in MyJFrame): public class FullScreen extends JFrame { private static final long serialVersionUID = 1L; private GraphicsDevice device; private

Java - Custom Shape Panels?

谁说胖子不能爱 提交于 2019-12-01 13:22:58
I am working on an application that involves the user requiring to hover over several moving dots on the screen in order to launch specific popups. At the moment, i am listening for mouseMoved events on the JPanel onto which the dots are rendered, and then launching the required pop ups whenever the cursor is within a specific distance of a dot. When i have hundreds of dots - this probably becomes quite expensive. Wouldnt the ideal solution be to represent my 'dots' as small components and register a mouse listener with each dot? Does anyone know how i might represent a small ellipse with a

drawing shape objects in java (draggable,resizable and can rotate)

断了今生、忘了曾经 提交于 2019-12-01 13:22:55
I am trying to draw shapes (triangle, rectangle, square and circle) that can be used in creating a picture. A user should be able to place a shape on a canvas and drag it around or even enlarge it to create a desired picture. I tried overriding the paintComponent() of a JPanel to achieve this but realize that the Jpanels shape remains a square so when you have a circle you can still drag it even if u are not necessarily touching it as it is within a square and also having difficulty drawing the triangle What libraries would you suggest? The Shape interface and derived classes, such as Path2D,