jpanel

When does a JTabbedPane component get its size?

守給你的承諾、 提交于 2019-12-11 01:24:35
问题 I need to know the size of a JPanel when I add it to a JTabbedPane to compute other values. If I call the add(Component) method, when does the Component get its size? For example, JTabbedPane tabbedPane = new JTabbedPane(); JPanel panel = new JPanel(); panel.setBackGround(Color.RED); // pretty colors! tabbedPane.add(panel); int newTabIndex = tabbedPane.indexOfComponent(panel); tabbedPane.setSelectedIndex(newTabIndex); Thank you in advance! Edit @mKorbel suggested setting the visibility of the

Java background JFrame with a Jpanel arranging images in a grid

◇◆丶佛笑我妖孽 提交于 2019-12-11 01:17:04
问题 so I've been working on my program and I am having trouble getting setting up a JFrame with a background image of a network map and then setting a JPanel using a MigLayout on top of the JFrame which will allow me to place images in accordance to the network map. I have seen several different ways on how to set a background image and have tried using an example I found elsewhere on this site but it's not quite working. Also, I researched more on this and found that having a JPanel ontop of a

Does g.drawImage() render only the part of the image visible on a JPanel, or does it “keep in mind” the rest of the image?

折月煮酒 提交于 2019-12-11 01:11:24
问题 Let's say we have the following code: (in a class that extends JPanel ): public void paintComponent(Graphics g) { g.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null); } If dx1 and dy1 are negative or dx2 and dy2 are larger than the width of the JPanel (in other words, part of the image will be off-screen), does drawImage() adjust what is rendered so that it only "pays attention to" the part visible on the JPanel ? I am curious about this because if I draw a very large image on

java huge BufferedImage in JScrollPane

你。 提交于 2019-12-11 01:06:43
问题 I need to fit a huge image (BufferedImage to access colors etc) into a JScrollPane derived class. Nothing very hard until there. The image is a JPG scan of an A3 sample of material, its size is 13030x20840 pixels, 24bits, and weights 12MB on disk -> about 800MB in RAM. I embedded the BufferedImage into a Jpanel, which lies as the Scrollpane's view. When I try to scroll/drag my image, it takes seconds to respond, so it is not very handy. I need your help in order to know what I should do to

Resize JFrame to JPanels inside JLayeredPane

与世无争的帅哥 提交于 2019-12-11 00:59:39
问题 I'm working on a Swing GUI using the JLayeredPane . The JFrame has a JLayeredPane which contains two JPanel s. Later I want to display some components in the JPanel s, I cut this part of the code to make it shorter for you. How do I resize the JFrame to the sizes of the JPanel s? frame.pack() does not work and without the line setting the preferred size the GUI will show with minimal size. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt

Drawing on a JPanel

核能气质少年 提交于 2019-12-11 00:33:09
问题 I'm start with create RubicPanel class extended from JPanel from NetbeanIDE set it to black background, put it on a JFrame and I start to draw on it by using another class like this. public class Drow { private final int SquareSize = 99; public void DrowRubic(RubicEntity GameRubic, RubicPanel rPanel) { Graphics g = rPanel.getGraphics(); g.setColor(Color.pink); g.fillRect(0, 0, 301, 301); int CurrentFace = GameRubic.getDirection(1); for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { DrowSquare

How to paint JComponent in JComponent?

久未见 提交于 2019-12-11 00:18:44
问题 I have strange problem with JComponent. I am trying to create my own JComponent and so I need to compose my JComponents together. I wanted to paint JButton in my JComponent JDial: public class JDial extends JComponent { private static final long serialVersionUID = 3364481508702147328L; public JDial() { JButton b = new JButton("test"); this.add(b); } } But that just paint nothing. Even more interesting is that this one works well: public class JDial extends JPanel { private static final long

JPanel gets resized of another JPanel is shown

大兔子大兔子 提交于 2019-12-10 23:56:57
问题 I have a question about nested BoxLayouts. I want to build a DropDownPanel which consists of 2 sub-Panels: a header at the top and a body at the bottom. The body is initially hidden. By clicking on the header you can toggle the visibility of the body and show its contents (like expand/collapse). In general this works fine. However there is some strange behaviour: If only one DropDownPanel is expanded and the other is collapsed then the collapsed DropDownPanel gets resized and floated to the

Overlapping components in JPanel

廉价感情. 提交于 2019-12-10 23:29:05
问题 I have a JButton and a Point (it's motion controlled by leap motion) on the same JPanel. However, they are overlapping with JButton on top. Is there a way to have my Point always on top in the JPanel application window? Here's a code snippet: public leapPanel() { setLayout(null); //18-12-13 setBackground(Color.WHITE); setVisible(true); //18-12-13 button = new JButton(); button.setBounds(100, 150, 100, 100); button.setBackground(Color.BLACK); add(button); points[nPoints] = new Point(PWIDTH/2,

Java Swing Gridlayout: Accessing Specific Coordinate

余生颓废 提交于 2019-12-10 23:23:23
问题 I'm creating a Java swing GUI and I have formatted a JPanel to use a GridLayout. I need to access a specific "box" (i.e. specific coordinate) of the grid, but I cannot see a way to do so. How can I do this? 回答1: You shouldn't depend on GUI code (the View) to give you information about program data (the model). The best solution would be to "know" which component is where from the start--maybe you should have a data structure (2D array?) that holds the components and is updated whenever