jpanel

How to add components to JFrame once it's visible without having to resize it?

别来无恙 提交于 2019-12-30 12:10:10
问题 I have a program where I have a JFrame with a JButton in it. When the user clicks the JButton , all Components of the JFrame are removed, and a JPanel with red background is added to it. When I click the JButton , that red JPanel does not become visible unless I resize the JFrame (I am using Windows 7). Is there a way to achieve what I want without having to manually resize the JFrame ? Here is a part of the code I am using: public class Demo implements ActionListener{ public static void main

How to make a JPanel inside a JFrame fill the whole window?

自作多情 提交于 2019-12-30 10:29:49
问题 In the below example, how can I get the JPanel to take up all of the JFrame? I set the preferred size to 800x420 but it only actually fills 792x391. import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.image.BufferStrategy; import javax.swing.JFrame; import javax.swing.JPanel; public class BSTest extends JFrame { BufferStrategy bs; DrawPanel panel = new DrawPanel(); public BSTest() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new

How to make a JPanel inside a JFrame fill the whole window?

我与影子孤独终老i 提交于 2019-12-30 10:29:49
问题 In the below example, how can I get the JPanel to take up all of the JFrame? I set the preferred size to 800x420 but it only actually fills 792x391. import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.image.BufferStrategy; import javax.swing.JFrame; import javax.swing.JPanel; public class BSTest extends JFrame { BufferStrategy bs; DrawPanel panel = new DrawPanel(); public BSTest() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new

Set the JPanel size to fill parent with little margin

浪尽此生 提交于 2019-12-30 05:28:05
问题 I have two Jpanel ( JpanelLeft and JpanelLeftContent ) how can i make the JpanelLeftContent fill parent size with a little margin on the left an right side. i have tried different layout and tried to modify the hgap and vgap values, but none of them give me a good result. JPanel JpanelLeft = new JPanel(); JPanel JpanelLeftContent = new JPanel(); JpanelLeft.add(JpanelLeftContent); And if possible how can i make the JpanelLeftContent look like a rounded rectangle as shown in the picture. 回答1:

Resizing Path2D circle by clicking and dragging its outer edge

拟墨画扇 提交于 2019-12-29 08:25:12
问题 So, when I click and drag a Path2D circle on my JPanel, it is resizing. The problem is that when I initially click-and-drag it, the circle jumps to a smaller size, but then resized correctly as you click and drag. The easiest way to demonstrate is to run the runnable code below. I know I need to fix this code: @Override public void mouseDragged(MouseEvent e) { int mouseX = e.getX(); int mouseY = e.getY(); if (resizing) { System.out.println("resizing"); Rectangle bounds = shapes.get

How to Export JPanel with scrollable into pdf file

瘦欲@ 提交于 2019-12-29 08:14:13
问题 i have design a jpanel with so many swing components with scrollable capability. i want to export whole Jpanle into pdf file.but i am not able to export whole Jpanle. I have use itext for pdf generation. My problem is that i am not able to export whole jpanel into pdf. When i export half of Jpanel components export.but half portion do not export. this is my code. public void PrintFrameToPDF(JPanel c, File file) { try { Document d = new Document(); PdfWriter writer = PdfWriter.getInstance(d,

JTable: Buttons in Custom Panel in Cell

旧街凉风 提交于 2019-12-29 06:26:30
问题 I want to be able to have a JPanel in a cell with a JButton that does some work when clicked. I looked for howtos about Cell Editors, but all examples talk about replacing the cell with another component (e.g. replace an int with a JTextField etc.) My situation is a little different: I have the following ADT class MyClass { public String title; public String url; public String path; public int annotations; } I created a custom table cell model that has 1 column and the class for that column

JTable: Buttons in Custom Panel in Cell

南笙酒味 提交于 2019-12-29 06:26:24
问题 I want to be able to have a JPanel in a cell with a JButton that does some work when clicked. I looked for howtos about Cell Editors, but all examples talk about replacing the cell with another component (e.g. replace an int with a JTextField etc.) My situation is a little different: I have the following ADT class MyClass { public String title; public String url; public String path; public int annotations; } I created a custom table cell model that has 1 column and the class for that column

Java: vertical alignment within JPanel

烂漫一生 提交于 2019-12-29 05:06:28
问题 I am trying to vertically align (center) both JLabels inside one JPanel. JPanel panel = new JPanel(); panel.setPreferredSize(size); JLabel label1 = new JLabel(icon); JLabel label2 = new JLabel("text"); panel.add(label1); panel.add(label2); I have tried using setAligmentY() with no success. Both labels always appear on the top of JPanel. UPD: Labels should be located next to each other like using FlowLayout, but in the middle of the JPanel. 回答1: Use a GridBagLayout with the default constraints

How can I align all elements to the left in JPanel?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-29 04:27:46
问题 I would like to have all elements in my JPanel to be aligned to the left. I try to do it in the following way: JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.setAlignmentX(Component.LEFT_ALIGNMENT); As a result Java use left side of all elements as a position of the element and then put all elements in the center (not left part) of the JPanel. 回答1: The easiest way I've found to place objects on the left is using FlowLayout. JPanel panel = new