jpanel

Java Swing - how to show a panel on top of another panel?

99封情书 提交于 2019-11-27 03:57:03
I wish to have an internal (non window) dialog to ask for member input. I would like the dialog to be placed centrally on an existing JPanel. I have looked at layeredpanes and these seem unusable due to only having a single layout manager (or no layout manager) across all the panes. I guess I could try to override JLayeredPane and provide a custom layout but this seems extreme. Glass panes don't seem to be appropriate either. How can this be done? Is there no usable concept of z-indexes in Swing? EDIT The reason Layered Panes weren't appropriate was due to the lack of a layout manager per

Dragging a JLabel with a TransferHandler (Drag and Drop)

人走茶凉 提交于 2019-11-27 03:37:22
问题 I am using a TransferHandler to pass data from a JPanel to a JTextArea as a JLabel (Click somewhere in the left panel to create the JLabel to drag) The transfer of the data works fine, but I'd like to also "show" the JLabel as its being dragged along with the mouse pointer. If you comment out dropLabel.setTransferHandler(new TransferHandler("text")); dropLabel.getTransferHandler().exportAsDrag(dropLabel, e, TransferHandler.COPY); you will see how I want it to look. (but of course then the

JPanel Padding in Java

不想你离开。 提交于 2019-11-27 03:36:48
I have a formatting question for my Java swing application. It should be fairly straightforward, but I am having difficulty finding any aid (Every topic seems to be regarding removing any default padding in JPanel). The text in my various JPanels hug the sides and top, touching the colored borders: how can I add padding? Thank you. Julien Vermillard Set an EmptyBorder around your JPanel . Example: JPanel p =new JPanel(); p.setBorder(new EmptyBorder(10, 10, 10, 10)); When you need padding inside the JPanel generally you add padding with the layout manager you are using. There are cases that you

JPanel keylistener

梦想与她 提交于 2019-11-27 03:24:21
问题 I am trying to add a key listener that holds a JTabbedPane . It should switch the tabs when ctrl + tab is received. But the keypressed event is never sent I tried adding it to the panel and to the tabbed object - but with no success. Here is my code SwitchTabsListener ctrlTabListener = new SwitchTabsListener(genericTabbedPanel); jMainFrame.addKeyListener(ctrlTabListener); genericTabbedPanel.addKeyListener(ctrlTabListener); 回答1: In a typical fashion, your key event is not intercepted by the

Basic code to display a pdf in an existing JPanel?

半城伤御伤魂 提交于 2019-11-27 02:59:51
问题 I have an existing interface that has a JPanel for displaying pdf files. It is important to display the pdf inside this inteface and not open a new window. How can I display a pdf on the JPanel without using unnecessary code (libraries) if possible? 回答1: if you want to render PDF content and ignoring the orginal format (boldness, font size.. etc) you can parse PDF using any PDF parser(PDFBox, Tika .. etc) and then set the string result to any text Component (JTextFiled or JTextArea).

Drawing an Image to a JPanel within a JFrame

有些话、适合烂在心里 提交于 2019-11-27 02:49:19
问题 I am designing a program that contains two JPanels within a JFrame, one is for holding an image, the other for holding GUI components(Searchfields etc). I am wondering how do I draw the Image to the first JPanel within the JFrame? Here is a sample code from my constructor : public UITester() { this.setTitle("Airplane"); Container container = getContentPane(); container.setLayout(new FlowLayout()); searchText = new JLabel("Enter Search Text Here"); container.add(searchText); imagepanel = new

Java - set opacity in JPanel

十年热恋 提交于 2019-11-27 02:39:11
问题 Let's say I want to make the opacity of a JPanel %20 viewable? I don't mean setOpaque (draw or not draw) or setVisible (show or hide)... I mean make it see-through JPanel.. you know? Is this possible? 回答1: panel.setBackground( new Color(r, g, b, a) ); You should also look at Backgrounds With Transparency to understand any painting problems you might have when you use this. 回答2: Use the alpha attribute for the color. For instance: panel.setBackground(new Color(0,0,0,64)); Will create a black

JPanel doesn't update when adding Component in another class

瘦欲@ 提交于 2019-11-27 02:21:58
I'm fairly new to Java Swing and I'm running into a few problems. As a side question, when making a fairly large Java Swing Application, what is the best way to split up code? In my case I want to have an application that has a layout just as Microsoft Word where there is a JToolBar filled with buttons and a main JPanel where changes are made based on the buttons pressed in the Tool Bar. So as shown in the code below, I have a JFrame and I call the MainPanel class in order to create a panel and add a ToolBar with a button. When the button is pressed it adds a button to the panel. The problem

Replacing JPanel with JPanel in a JFrame

自闭症网瘾萝莉.ら 提交于 2019-11-27 02:15:04
I have a class that extends JFrame, and it has a BorderLayout. It has two private instance variables of type JPanel. They represent panels of buttons and are called flipButton and confidenceButtons. When you click on the button, the panel of buttons is replaced by the other panel of buttons. That is, if you click on a button in flipButton, flipButton is replaced by confidenceButtons. I tried to do it like this: private class FlipListener implements ActionListener{ public void actionPerformed(ActionEvent e){ remove(flipButton); add(confidenceButtons,BorderLayout.SOUTH); validate(); ... } }

FlowLayout on top of GridLayout not working

纵饮孤独 提交于 2019-11-27 02:14:49
I'm trying to create a hangman game and so far it's coming along GREAT, but the layout design just doesn't seem to fall into place! The alphabet is supposed to end up in a FlowLayout order on top of the Hangman picture with the buttons "Restart", "Help" "Add New Word" and "Exit" at the bottom! What am I doing wrong? import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; public class Hangman extends JFrame { int i = 0; static JPanel panel; static JPanel panel2; static JPanel panel3; public Hangman() { JButton[] buttons = new JButton[26]; panel = new JPanel(new